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:
Mixpanel by default can only track utm parameters as they have mentioned in their documentation here – https://help.mixpanel.com/hc/en-us/articles/115004561786-Track-UTM-Tags
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:
- 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.
- 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.
- 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.
- 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 – https://www.analyticsmania.com/post/transfer-utm-parameters-google-tag-manager/