Last Touch UTM Tags - Articles From the Archive

  • 17 July 2019
  • 2 replies
  • 175 views

Userlevel 6
Badge +4

Each week, Mixpanel will release articles from our archives to help you get the most out of Mixpanel. Follow the Topic Tag #fromthearchive to subscribe to these posts and get alerted when they drop.


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.

 


2 replies

Hello! Sorry if this is a dumb question- I’m fairly new to mixpanel and I’m trying to track which traffic are coming in to our site using the different URLs with UTMs. My ideal outcome for this is that I can set up different funnels for traffic that came in through UTM 1, another for UTM 2, another for UTM 3, and so on. Is that possible?

 

If it is, how do we set that up? We already added the code to collect last touch UTMs to our site but I’m not sure what event records this data. I already tried using the events $current_url$referrer, and $initial_referrer but we haven’t been seeing data after we ran some tests.

 

Hoping to get some help 🙂 Thanks! 

Userlevel 5
Badge +3

@lenlituhoy —

Certainly no dumb questions, I’m glad you asked! The best part about asking questions here in QBQ is that it helps the next person looking for the same answer as you!

I’m trying to track which traffic are coming in to our site using the different URLs with UTMs. My ideal outcome for this is that I can set up different funnels for traffic that came in through UTM 1, another for UTM 2, another for UTM 3, and so on. Is that possible?

Yes, you can do this! If you are using our Javascript SDK the following UTM Parameters are tracked by default.

  • utm_source: track the source where traffic is coming from, including a website or advertiser
  • utm_medium: track the advertising medium, including email and banner ads
  • utm_campaign: track the campaign name associated with the traffic
  • utm_content: track the specific link within in an ad that a user clicked
  • utm_term: track keywords associated with campaigns

(more detail here)

Any utm tags  (utm_source, utm_medium, etc.) associated with the link a customer clicked to arrive at your domain will be tracked and stored as a super property and sent with each event. Each utm will be collected under its own property, and Mixpanel only tracks first touch UTM parameters by default but you can use this post to track last touch UTMs as well.

 

If it is, how do we set that up? We already added the code to collect last touch UTMs to our site but I’m not sure what event records this data. I already tried using the events $current_url$referrer, and $initial_referrer but we haven’t been seeing data after we ran some tests.

The event would be any event that is sent via your client-side Javascript SDK. Let’s take “Page View” for example. If you are creating an Insights report and you query for the Page View event, then you can breakdown the report by the UTM property that you are collecting: ie, utm_source.

The properties $current_url, $referrer, and $initial_referrer would not track this UTM property, but you may see similar data points. For example, $current_url may include the URL with the UTMs, $referrer may include the UTMs if it is the referring URL for a subsequent page view event and $initial_referrer could include the UTMs if it is for a new user. 

 

Let me know how it goes!

Reply