Last Touch UTM Tags

This article describes how to tie users’ most recent UTM tags (last touch attribution) to their actions.

Tracking Last Touch UTM Tags

Last touch attribution allows you to see how a user found your site most recently.

You can use last touch UTM properties to measure the effectiveness of various marketing campaigns through Mixpanel’s Insights report.

You could also leverage Mixpanel’s Funnels report to determine if specific campaigns impacted conversions.

If a user eventually makes a purchase or completes some other event of consequence, you can use last touch UTM tags to determine what acquisition channel brought them to the site most recently.

First touch UTM tags are automatically tracked by Mixpanel’s JavaScript Library and stored in the Mixpanel cookie so that they can be referenced on subsequent sessions.

First touch attribution allows you to see how a user originally found your site, even for events that occur after the first visit.

If a user eventually makes a purchase or completes some other event, you want to know what acquisition channel brought them to your site originally, even if it’s been some time since they first arrived.

Collecting Last Touch UTMs

This code automatically parses and registers last touch UTM tags as super properties.

Paste the code below the Mixpanel JavaScript snippet that you add to your site to track events.

function getQueryParam(url, param) {
// Expects a raw URL
param = param.replace(/[[]/, "\[").replace(/[]]/, "\]");
var regexS = "[\?&]" + param + "=([^&#]*)",
   regex = new RegExp( regexS ),
   results = regex.exec(url);
if (results === null || (results && typeof(results[1]) !== 'string' && results[1].length)) {
 return '';
 } else {
 return decodeURIComponent(results[1]).replace(/\W/gi, ' ');
 }
};
function campaignParams() {
var campaign_keywords = 'utm_source utm_medium utm_campaign utm_content utm_term'.split(' ')
   , kw = ''
   , params = {}
   , first_params = {};
var index;
for (index = 0; index < campaign_keywords.length; ++index) {
 kw = getQueryParam(document.URL, campaign_keywords[index]);
 if (kw.length) {
   params[campaign_keywords[index] + ' [last touch]'] = kw;
 }
}
for (index = 0; index < campaign_keywords.length; ++index) {
 kw = getQueryParam(document.URL, campaign_keywords[index]);
 if (kw.length) {
   first_params[campaign_keywords[index] + ' [first touch]'] = kw;
 }
}
mixpanel.people.set(params);
mixpanel.people.set_once(first_params);
mixpanel.register(params);
}
campaignParams();

You can remove the .people.set() calls if you don’t plan to store user profiles.

mixpanel.register(params) is the function that captures these last touch UTM parameters and registers them as super super properties to be tracked with all future events.

Tracking UTM Parameters as Properties of a User’s Profile

Mixpanel’s super properties are only attached to events.

The code above allows you to filter and segment events by UTM parameters. However, your people profiles will not contain attribution data, unless you specifically set your UTM parameters as people properties using .people.set() and mixpanel.identify() in tandem.

To create a user profile, insert the mixpanel.identify() call in the body of the HTML page collecting these UTM campaign parameters.

In combination with the code above, this call creates a user profile containing both the first and last touch UTM parameters for every user that loads the page.

This call is especially valuable for tracking lifetime revenue using Mixpanel’s revenue report.

You’ll want to store first and last touch UTM parameters as people properties to segment users’ lifetime revenue by both the original campaign they came from, as well as the most recent campaign of which they interacted.

Mixpanel users tend to not send notifications based on UTM parameters, so it may not be worth your time to change your code to capture this data if you’re not using revenue reports.

Is this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.