Skip to content

Commit 74e9e08

Browse files
authored
Merge pull request #53 from Szasza/feature/adding-click-tracking-to-domain
adding click_tracking support, updating documentation on open_tracking availability
2 parents 4726345 + 08a5fe8 commit 74e9e08

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

docs/data-sources/domain.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ The following attributes are exported:
3939
* `smtp_password` - The password to the SMTP server.
4040
* `wildcard` - Whether or not the domain will accept email for sub-domains.
4141
* `spam_action` - The spam filtering setting.
42+
* `open_tracking` - The open tracking setting.
43+
* `click_tracking` - The click tracking setting.
4244
* `web_scheme` - The tracking web scheme.
4345
* `receiving_records` - A list of DNS records for receiving validation.
4446
* `priority` - The priority of the record.

docs/resources/domain.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The following arguments are supported:
3838
* `dkim_selector` - (Optional) The name of your DKIM selector if you want to specify it whereas MailGun will make it's own choice.
3939
* `force_dkim_authority` - (Optional) If set to true, the domain will be the DKIM authority for itself even if the root domain is registered on the same mailgun account. If set to false, the domain will have the same DKIM authority as the root domain registered on the same mailgun account. The default is `false`.
4040
* `open_tracking` - (Optional) (Enum: `yes` or `no`) The open tracking settings for the domain. Default: `no`
41+
* `click_tracking` - (Optional) (Enum: `yes` or `no`) The click tracking settings for the domain. Default: `no`
4142
* `web_scheme` - (Optional) (`http` or `https`) The tracking web scheme. Default: `http`
4243

4344
## Attributes Reference
@@ -50,6 +51,8 @@ The following attributes are exported:
5051
* `smtp_password` - The password to the SMTP server.
5152
* `wildcard` - Whether or not the domain will accept email for sub-domains.
5253
* `spam_action` - The spam filtering setting.
54+
* `open_tracking` - The open tracking setting.
55+
* `click_tracking` - The click tracking setting.
5356
* `web_scheme` - The tracking web scheme.
5457
* `receiving_records` - A list of DNS records for receiving validation. **Deprecated** Use `receiving_records_set` instead.
5558
* `priority` - The priority of the record.

mailgun/resource_mailgun_domain.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ func resourceMailgunDomain() *schema.Resource {
8181
Default: false,
8282
},
8383

84+
"click_tracking": {
85+
Type: schema.TypeBool,
86+
Optional: true,
87+
ForceNew: false,
88+
Default: false,
89+
},
90+
8491
"web_scheme": {
8592
Type: schema.TypeString,
8693
Optional: true,
@@ -274,6 +281,7 @@ func resourceMailgunDomainUpdate(ctx context.Context, d *schema.ResourceData, me
274281
var newPassword string = d.Get("smtp_password").(string)
275282
var smtpLogin string = d.Get("smtp_login").(string)
276283
var openTracking = d.Get("open_tracking").(bool)
284+
var clickTracking = d.Get("click_tracking").(bool)
277285
var webScheme = d.Get("web_scheme").(string)
278286

279287
// Retrieve and update state of domain
@@ -304,10 +312,23 @@ func resourceMailgunDomainUpdate(ctx context.Context, d *schema.ResourceData, me
304312
}
305313
}
306314

315+
if currentData.Get("click_tracking") != clickTracking {
316+
var clickTrackingValue = "no"
317+
if clickTracking {
318+
clickTrackingValue = "yes"
319+
}
320+
errc = client.UpdateClickTracking(ctx, d.Get("name").(string), clickTrackingValue)
321+
322+
if errc != nil {
323+
return diag.FromErr(errc)
324+
}
325+
}
326+
307327
if currentData.Get("web_scheme") != webScheme {
308328
opts := mailgun.UpdateDomainOptions{}
309329
opts.WebScheme = webScheme
310330
errc = client.UpdateDomain(ctx, name, &opts)
331+
311332
if errc != nil {
312333
return diag.FromErr(errc)
313334
}
@@ -334,6 +355,7 @@ func resourceMailgunDomainCreate(ctx context.Context, d *schema.ResourceData, me
334355
opts.WebScheme = d.Get("web_scheme").(string)
335356
var dkimSelector = d.Get("dkim_selector").(string)
336357
var openTracking = d.Get("open_tracking").(bool)
358+
var clickTracking = d.Get("click_tracking").(bool)
337359

338360
log.Printf("[DEBUG] Domain create configuration: %#v", opts)
339361

@@ -357,6 +379,13 @@ func resourceMailgunDomainCreate(ctx context.Context, d *schema.ResourceData, me
357379
return diag.FromErr(errc)
358380
}
359381
}
382+
if clickTracking {
383+
errc = client.UpdateClickTracking(ctx, d.Get("name").(string), "yes")
384+
385+
if errc != nil {
386+
return diag.FromErr(errc)
387+
}
388+
}
360389

361390
d.SetId(name)
362391

@@ -470,5 +499,11 @@ func resourceMailgunDomainRetrieve(id string, client *mailgun.MailgunImpl, d *sc
470499
}
471500
d.Set("open_tracking", openTracking)
472501

502+
var clickTracking = false
503+
if info.Click.Active {
504+
clickTracking = true
505+
}
506+
d.Set("click_tracking", clickTracking)
507+
473508
return &resp, nil
474509
}

mailgun/resource_mailgun_domain_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func TestAccMailgunDomain_Basic(t *testing.T) {
3838
"mailgun_domain.foobar", "force_dkim_authority", "true"),
3939
resource.TestCheckResourceAttr(
4040
"mailgun_domain.foobar", "open_tracking", "true"),
41+
resource.TestCheckResourceAttr(
42+
"mailgun_domain.foobar", "click_tracking", "true"),
43+
resource.TestCheckResourceAttr(
44+
"mailgun_domain.foobar", "receiving_records.0.priority", "10"),
4145
resource.TestCheckResourceAttr(
4246
"mailgun_domain.foobar", "web_scheme", "https"),
4347
resource.TestCheckResourceAttr(
@@ -171,6 +175,7 @@ resource "mailgun_domain" "foobar" {
171175
wildcard = true
172176
force_dkim_authority = true
173177
open_tracking = true
178+
click_tracking = true
174179
web_scheme = "https"
175180
}`
176181
}

0 commit comments

Comments
 (0)