Tracking User Interactions in Email With Google Analytics
This is a follow up to Tracking Actions in Interactive Email which covered the mechanics of tracking user interactions in email using the selective loading of background images. This post will cover how to use Google Analytics to serve up the tracking pixel and provide the tracking reports.
A not so well known feature of Google Anaytics (GA) is the ability to track email events – specifically tracking email opens. By carefully constructing your analytics pixel URL you can also use that to track user interactions in your kinetic campaigns.
If you don’t yet have a Google Analytics tracking ID (UA-XXXXX), follow this link to get one.
Analytics Link Structure
Following this guide your tracker pixel URL will look something like this.
v=1&tid=UAXXXXXX&t=event&cid=123123123&
ec=kinetic&ea=interact&el=unit1&
cn=campaign_20160130&cs=email
cid = Unique session id (recipient id)
t = Tracking type (set to “event”)
ec = Event category
ea = Event action
el = Event label (optional)
cn = Campaign name (optional)
cs = Campaign source (required for campaign tracking)
There are a few more variables that you can track using the GA link such as campaign medium (cm) and custom variables. In fact you can go so far as to use custom dimensions to tie users to visits to your website – but for our purposes we’ll stick with the basic set.
Assigning values to the variables
Depending on your familiarity with Google Analytics, you may already have an established way to use the GA variables so the following is just one of several possible ways to assign them.
Set the “tid” variable to your GA tracking ID, and leave the “t” variable set to “event” to let GA know you’re tracking an event as opposed to a page view.
Event category (ec) can be seen as a way to group your events. I like to set mine to “kinetic”.
Event action (ea) is where you can specify the type of event tracked – ie interact, open, client-type, animation etc.
Event label (el) is optional and you can use it to track the type of interactions be it generic (ie. rollover, clicked) or specific such as the unit that was interacted with (ie. unit1, unit2 etc). You can use this to track the client type as well (webkit, mobile, gmail-webmail etc).
You can use campaign name (cn) and campaign source (cs) to track your reports by email campaign. Campaign source is required if you want to track by campaign name, and you can use any value – I just use “email” here.
Unique Session ID (cid)
The unique session id (cid) is an identifier that uniquely identifies the user session. Normally you’d use the recipient’s email address, but unfortunately Google does not want you to do this. According to the docs, information passed to GA must not be personally identifiable information (pii).
In order to comply with the PII requirement, you may have to resort to your Email Service Provider (ESP) to give you some sort of ID that identifies the user other than their email. MailChimp has a merge tag *|UNIQID|* that produces a user’s ID.
Integrating the GA Pixel
Now that you’ve got your GA pixel URL you can integrate the pixel into your campaigns.
For background see: Tracking Interactions in Interactive Email.
Here are some examples based on the code used in the referenced article:
(Replace the GA tracking ID (tid), session ID (cid) and campaign name (cn) variables)
Open Tracking:
Lets start with the basic open tracking pixel that will record an event each time an email is opened (assuming images are displayed).
<img src="http://www.google-analytics.com/collect?v=1& tid=UA-XXXXXX&t=event&cid=*|UNIQID|*&cn=test_campaign& cs=email&ec=kinetic&ea=open" width=1 height=1>
Rollover:
.img-swap:hover .tpixel{ background-image:url(http://www.google-analytics.com/collect?v=1& tid=UA-XXXXXX&t=event&cid=*|UNIQID|*&cn=test_campaign& cs=email&ec=kinetic&ea=interact&el=rollover); }
Carousel:
This won’t actually work in MailChimp since it doesn’t support form elements like radio
.radio2:checked ~ .carousel .tpixel{ background-image:url(http://www.google-analytics.com/collect?v=1& tid=UA-XXXXXX&t=event&cid=*|UNIQID|*&cn=test_campaign& cs=email&ec=kinetic&ea=interact&el=radio2_select); } .radio3:checked + .carousel .tpixel{ background-image:url(http://www.google-analytics.com/collect?v=1& tid=UA-XXXXXX&t=event&cid=*|UNIQID|*&cn=test_campaign& cs=email&ec=kinetic&ea=interact&el=radio3_select); }
Mobile opens
<style> @media screen and (max-device-width: 600px) { .mobile-pixel{ background-image: url(http://www.google-analytics.com/collect? v=1&tid=UA-XXXXXX&t=event&cid=*|UNIQID|* &cn=test_campaign&cs=email&ec=kinetic &ea=client-type&el=mobile); } } </style> <div class="mobile-pixel"></div>
Testing Your Pixel
One of the cool features of Google Analytics is the ability to see realtime events as they happen. This allows you to instantly test if your pixels are configured properly. You can send a test campaign (or just load the HTML within a browser) and your interactions will appear immediately in the realtime view.
You can get to the realtime view through the left side menu Real-Time -> Events. Clicking on the “Events (last 30 min)” option allows you to see the total number of events per event action fired.
From the above animation you can observe that the delay in the recording of an event is relatively short. Also note that due to the fact that once the pixel is loaded in a page it is not retrieved again unless the page is refreshed, activating the rollover event the second time did not produce a recorded event.
Reporting
Here’s the exciting part. You can get to the events reporting section in Google Analytics through the left side menu Behavior -> Events -> Top Events.
Once you’re at Top Events, you can see all the events broken down by event category. Clicking on the “kinetic” event category, you can see all the event actions as shown below:
Total Events and Unique Events
In the above screenshot, you can see two metrics Total Events and Unique events. Total Events is basically the number of times the pixel for an event has been loaded.
However Unique Events is not the number of unique users that have triggered an event. It refers to the number of sessions that an event has taken place in. For example if a single user opened an email 10 times in 3 days, Total Events would show 10 as expected, but Unique Events will actually show 3 and not 1. Google Analytics starts determines a new session has ended if it detects no events from a user after 30 minutes. See this article for more information
Counting Users
In order to show how many unique users has triggered an event, you’d need to add the Users column using a Custom Report.
This video below shows you how to do it:
Analytics Galore
With Google Analytics you have a free and powerful way to track user interactions with your email. I’d love to hear any insights you find with your data!
Also if you happen to know the merge tags for “subscriber id” for your Email Service Provider (ie. Responsys, ExactTarget etc.), go ahead and comment below or send me a note.
Hi,
Thank you for your explanation about tracking mail user interactions with Google Analytics. I think the open-hits should not generate sessions, because the users are not on the site.
Is there a reason why you did not include the non interactive parameter (&ni=1) in the string?
Hey Wouter, thanks for bringing that up. Could you tell me where it skews your site stats? Google says that ni is meant to denote that the action was not initiated by the user but in this case an open is user initiated.
Hey there, really awesome blog, learned a lot:)). One question though – what happens if I dont specify a cn in the tracking pixel – will GA automatically parse the campaign name? If not, is there a way to get it to specify it based on utm_campaign? Thanks
Hey, thank you so much for the article. Really helpful,
I have one question that if I put the `Mobile opens` style and normal on email and open it in mobile, the event will fire twice.
Is there any way to prevent that?
I suggest using using different codes for mobile and desktop so you know which is fired, so even if the desktop one fires, when opened in mobile, you can simply deduct the desktop fires from mobile.
If you have to share pixel codes one way is to use the mobile pixel but change the media query to only target non mobile screens, but that would not work on clients that don’t support media queries like Outlook.
Hi,
how can I track event “click on button” in email?
Thank you :)
Hey Veronika, this technique will work if the button is interactive (it does not open a browser). If you want to trick clicks on “regular” buttons that open a landing page, you’d probably have to rely on reports in your ESP or you’d need some proxy links (like Bitly but NOT Bitly since some clients mark it as spam).