Repository navigation
Turn on Google Analytics link tracking when a campaign is created - #37
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_campaignalways sends atrackingblock:utm_campaign) is deterministic:pe-newsletter-plus the slugged campaign title. The title defaults to the edition file name, soeditions/2026-10-26-uk.htmlgivespe-newsletter-2026-10-26-uk.google_analytics=overrides it, for example for a webinar invite.opens,html_clicksandtext_clicksare Mailchimp's defaults, set explicitly so the click and open data that Teamverse reads stays on.update_campaigndoes 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 --checkandruff checkpass.pytest: 183 passed. New tests cover the name format, the 50-character cap, the request payload and the override.🤖 Generated with Claude Code