Skip to content

Turn on Google Analytics link tracking when a campaign is created - #37

Merged
PavelMakarchuk merged 1 commit into
mainfrom
ga-tracking-on-create
Nov 6, 2026
Merged

PavelMakarchuk merged 1 commit into
mainfrom
ga-tracking-on-create

Conversation

@PavelMakarchuk

Copy link
Copy Markdown
Contributor

Why

Mailchimp adds UTM tags to newsletter links only when a campaign has Google Analytics link tracking on, and that is a per-campaign setting. Campaigns this repo creates did not set it, so GA4 could not tell which visits came from which edition.

What changes

MailchimpClient.create_campaign always sends a tracking block:

"tracking": {
  "opens": true,
  "html_clicks": true,
  "text_clicks": true,
  "google_analytics": "pe-newsletter-2026-10-26-uk"
}
  • The GA name (utm_campaign) is deterministic: pe-newsletter- plus the slugged campaign title. The title defaults to the edition file name, so editions/2026-10-26-uk.html gives pe-newsletter-2026-10-26-uk.
  • It is capped at 50 characters, Mailchimp's limit for the field.
  • google_analytics= overrides it, for example for a webinar invite.
  • opens, html_clicks and text_clicks are Mailchimp's defaults, set explicitly so the click and open data that Teamverse reads stays on.
  • update_campaign does not change the GA name, so a renamed draft keeps its attribution.

Related

Teamverse (PolicyEngine/CRM#376) runs an hourly job that tags drafts with no GA name. With this change, drafts from this repo already have a name at creation, and that job leaves them alone. It stays as a backup for drafts made by hand in Mailchimp.

Checks

  • black --check and ruff check pass.
  • pytest: 183 passed. New tests cover the name format, the 50-character cap, the request payload and the override.

🤖 Generated with Claude Code

create_campaign now always sends tracking.google_analytics, so Mailchimp
adds utm_campaign to every link and GA4 attributes newsletter visits to
the edition. The name is deterministic: "pe-newsletter-" plus the slugged
campaign title, which defaults to the edition file name (2026-10-26-uk
gives pe-newsletter-2026-10-26-uk), capped at Mailchimp's 50 characters.
Callers can pass google_analytics to override it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PavelMakarchuk
PavelMakarchuk merged commit 71343df into main Nov 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant