About Google Analytics Tracking

Mandrill supports automatic Google Analytics tracking for your links. We need two pieces of information to add this tracking:

  1. A list of domains which are eligible for Google Analytics variables. Some links don’t work as intended when a query string is added, or if arbitrary things are added to the query string. To avoid this, you’ll tell Mandrill which links are intended to receive the Google Analytics variables.

  2. A Google Analytics campaign. What this actually means is up to you: it is frequently a Google search campaign, but you could technically put whatever tracking variable you want in here. It’s what gets added to the utm_campaign parameter. If no value is provided, the From address for the email is used by default.

Add Google Analytics Tracking

For our SMTP integration, use custom SMTP headers to set these variables:

  • X-MC-GoogleAnalytics: a comma-separated list of the domains to have Google Analytics tracking added

  • X-MC-GoogleAnalyticsCampaign: the value Mandrill will set for utm_campaign variable

For the API, when using the messages/send or messages/send-template endpoints, set the following within the message parameter:

  • google_analytics_domains: an array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically

  • google_analytics_campaign: optional string indicating the value to set for the utm_campaign tracking parameter

Be sure to include any subdomains used in your URLs so Google Analytics tracking can be added. For example, if your message contains links to both http://www.domain.com and http://domain.com, your google_analytics_domains array would look like:

"google_analytics_domains": [
            "www.domain.com",
            "domain.com"
        ],
. . .

And your X-MC-GoogleAnalytics header would look like:

X-MC-GoogleAnalytics: www.domain.com, domain.com

 

Note

It's not possible to change the source (utm_source) that's included when using Mandrill's automatic Google-Analytics tracking code. If you want more control over the parameters being added, we recommend adding the Google Analytics parameters manually before passing the emails to Mandrill for processing.