Select Page

Google analytics has it’s unique way to track traffic sources and attribute your user data to them. Here you can see what I am talking about:

GA Sources

Mixpanel by default can only track utm parameters as they have mentioned in their documentation here –

This means that with utm tracking you can track your Google ads, Facebook ads campaigns etc. in Mixpanel.

But what about other traffic sources like Direct, Organic and Referral where there are no utm parameters in the URL?

Here is the little hack for this:

Julius Fedorovicius has a nice blog post about how to track initial traffic source here –

In this blog post he talks about how you can track the initial traffic source and check some other sources that are bringing traffic to your site instead of just relying on GA’s last non-direct click attribution model.

The code mentioned in his blog post can be implemented using Google tag manager or directly into the site (if there’s a pro javascript developer on your side).

That code will set a cookie called initialTrafficSource into the web browser of the user having values of utm source, medium and campaign etc from the URL. No worries, if there is no utm parameters in the URL then it will automatically detect Direct, Referral and Organic traffic and will set the cookie’s value accordingly.

First the developer’s job is to understand the format of the cookie values.

The format of the initialTrafficSource cookie formatted as follows:|utmcmd=affl-link|utmccn=foo|utmcct=bar|utmctr=biz

  • utmcsr is campaign source
  • utmcmd is campaign medium
  • utmccn is campaign name
  • utmcct is campaign content
  • utmctr is campaign term

Now if the user will come from any of your utm tagged URL then it will be tracked automatically by Mixpanel as mentioned above. And when the user will come from the non utm tagged URL like organically or direct then his source value will be captured and will be saved in the initialTrafficSource cookie in his web browser.

The developer’s job is the make a javascript code which will do this:

  1. Check if there are UTM parameters in the URL or not. If there are UTM parameters in the URM of the first page the user has visited then do nothing.
  2. If there are no UTM parameters in the URL, then write a code which will read utm parameter values from the cookie initialTrafficSource and will create utm parameters in the URL.
  3. If UTM parameter values are added to the URL then they will be automatically picked by the Mixpanel.

Note: Developer has to make sure that the Mixpanel tracking code runs after his code so that when Mixpanel code runs, it will have UTM parameters added to the URL. Or the developer can pass UTM parameter values from one page to another so that if UTM parameters are not tracked on one page then they will be tracked on another page. Here is the article explaining that –

Pin It on Pinterest

Share This