Solved

UTM Parameters as People Properties

  • 9 December 2020
  • 7 replies
  • 307 views

Hi there,

I am using Mixpanel through Segment. From my website I trigger page views using

analytics.page();

and identify them using

analytics.identify("user_id_123");

In Segment I have

  • Use Mixpanel People - On
  • Traits & Properties - All Off
  • Automatically set all Traits as Super Properties and People Properties - On

I am getting events into Mixpanel, everything looks good, except this:

If I land on my website (from an incognito window) with UTM parameters set in the URL, that page view event will contain the right data (UTM Campaign = test for example). Then I navigate to a different page, the UTM Parameters disappear from the URL, as expected, the event sent to Mixpanel does not contain any UTM Parameters, and the user doesn’t have them set as People Properties.

I was under the impression that Mixpanel would do this automatically, did I read this wrong? Either way, how can I get the UTM data to be automatically associated with users (anonymous or logged in)?

Thanks in advance 🙂

icon

Best answer by anttonp 17 July 2021, 12:24

After a bunch of research and trial and error, we found the solution to this problem (the frustration was in reality a misunderstanding of Mixpanel’s documentation, which I’ll try to explain below). 

Mixpanel automatically tracks first-touch UTM codes, that’s correct. And it tracks them as ‘Super Properties’ (as you can see here. However, we thought that super properties were User/People properties, when in turn, they are Event properties. This is explain in this article

After realising this, we understood that, although Mixpanel’s JS library was automatically tracking UTMs, it wasn’t creating user attributes which is what we (and I believe a few in this thread) were after. And that’s when we bumped into this thread on the topic. We followed @stephanie ‘s instructions, and boom! We had what we needed. 

To recap, all we did was call the script below, that captures UTMs on its own, and sets them as user/people properties. The script creates first and last touch properties, to make sure you capture and keep both. 

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;
}
}
console.log(params);
console.log(first_params);
mixpanel.people.set(params);
mixpanel.people.set_once(first_params);
mixpanel.register(params);
mixpanel.identify();
}
campaignParams();

 

@Jaz-CommunityManager I believe that the confusion comes from a few misleading statements in this help article that might be worth slightly tweaking. DM me if you’d like us to go through it. 

Hope this helps! 

P.s.: Shoutout to @Kieranm for the good work here!

View original

7 replies

Userlevel 3
Badge +1

Is the UTM not being captured or not being updated? By default Mixpanel captured only first touch utm. So, if you are trying it for a user who already has a utm property set, it won’t update. Do you want to capture last touch utm too?

Hi Jaya, thanks for answering!

I am ok with first touch, that’s not really the problem.

My problem is that none of my users, including my own users when I specifically try to trigger this, have UTM params on their profile (like beside email, browser, city, etc. when I look at users under the Users screen and then click on one).

Also, none of the subsequent page views in a user’s visit have the UTM params set, even though the first page in the visit did. The landing page does contain the UTM params in the URL, you can see them in Mixpanel, and they even show up nicely formatted as “UTM Campaign” as a property of the page view event. But then that data is lost on the next page views.

I am going through Segment by the way.

I’m having the same problem. 

I have a React SPA and Segment.io integration.
When a new user comes for the first time with UTM params, the “Loaded page” and “Viewed page” events catch UTM params correctly, but the auto-identify event (that create an anonymous-id) doesn’t. 

I understand the anonymous Id should catch the UTM params and then after login or registration, the data should merge with the userId data. 

 

I am having the same issue and to be honest it’s quite frustrating when you go on and read help articles saying this happens automatically (when it really does not). 

 

Anyone with a fix?

Userlevel 3
Badge +5

@Jaya is this something you can help with?

We are having the same issue. We can see the utm-source come through to the event, but it looks impossible to get UTM parameters to appear in the user profile. 

As ‘Mixing the panel’ says above, it is frustrating as all documentation says that they should be automatically registered as super properties, but they aren’t. 

We are using the JS native library, and we are trying to see the first-touch UTM. 

After a bunch of research and trial and error, we found the solution to this problem (the frustration was in reality a misunderstanding of Mixpanel’s documentation, which I’ll try to explain below). 

Mixpanel automatically tracks first-touch UTM codes, that’s correct. And it tracks them as ‘Super Properties’ (as you can see here. However, we thought that super properties were User/People properties, when in turn, they are Event properties. This is explain in this article

After realising this, we understood that, although Mixpanel’s JS library was automatically tracking UTMs, it wasn’t creating user attributes which is what we (and I believe a few in this thread) were after. And that’s when we bumped into this thread on the topic. We followed @stephanie ‘s instructions, and boom! We had what we needed. 

To recap, all we did was call the script below, that captures UTMs on its own, and sets them as user/people properties. The script creates first and last touch properties, to make sure you capture and keep both. 

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;
}
}
console.log(params);
console.log(first_params);
mixpanel.people.set(params);
mixpanel.people.set_once(first_params);
mixpanel.register(params);
mixpanel.identify();
}
campaignParams();

 

@Jaz-CommunityManager I believe that the confusion comes from a few misleading statements in this help article that might be worth slightly tweaking. DM me if you’d like us to go through it. 

Hope this helps! 

P.s.: Shoutout to @Kieranm for the good work here!

Reply


Mixpanel