Self-Referrals and Cross-Domain Tracking in Google Analytics
Loves Data
It may not surprise readers of this blog that Google Analytics is just about our favourite tool. It has revolutionised the ability to track, monitor and analyse our website visitors to such an extent that it is easy to forget really how new and innovative it is. And, like everything in life, there are sometimes some little gotchas that are easy to forget about. One of those gotchas can arise when your website spans across more than one domain or sub-domain, and in this blog, we explain how to deal with this situation. If you think this doesn’t apply to you, don’t forget that, as far as your user tracking is concerned, your website includes any third-party payment processors and other external components and you need to consider these when implementing your tracking. Note for long-time readers: we blogged about this issue back in 2012, and if your site is still using the old-dated classic Google Analytics tracking code then what we wrote then still applies, but it’s high time you upgraded to Universal Analytics.
Self-referrals
Have you ever looked at your Google Analytics reports to see which third-party websites are sending traffic to your site and found rows which look like they are internal website traffic and not true referrals?
Maybe you are seeing subdomains of your main site, other hostnames that are really part of one bigger website that you run, or your payment processor (such as Paypal). These ‘self-referrals’, as they are known, need some special handling to track visitors correctly as they travel between the different domains that make up your website.
The Problem
When people are browsing and interacting with your website, you want their entire visit with your main site, its subdomains, and other parts of the whole to be all recorded, treated and analysed as a single website session. You want Google Analytics to recognise that it is the same person, on one single website session, who is visiting different parts of the site, including the subdomains and returning from your payment processor to your ‘thank you page’. Without fixing for cross-domain tracking, however, your reports are useless: for instance, it will look like all of your online sales have been brought about by traffic from PayPal and you will have no idea whether it is really your AdWords campaigns or email newsletter that is really responsible. Add an inflated count of sessions and proper analysis becomes impossible.
Technically, there are two things to worry about. First, you need Google Analytics to recognise that it’s the same person from the same browser who is visiting each of your subdomains and subsites. Secondly, you want Google Analytics to recognise that movement between your subdomains and subsites is all part of a single ‘session’. Luckily, fixing these is quite easy.
But First...
Before you go making any configuration changes, make sure you have Google Analytics tracking all the pages of your site. Often we find that some websites have pages that are missing tracking code. If this is the case for your website, you will still have self-referral traffic recorded as people move from the ‘hidden’ pages to your tracked pages and Google Analytics sees this as a new session referred from an untracked page on your site.
Subdomains
With multiple sub-domains, such as mysite.com, blog.mysite.com, etc., things are easy as, unlike the old days with classic Google Analytics, the modern Universal Analytics library and backend can cope with this situation ‘out-of-the-box’. Just make sure that you have set up your tracking code on your website properly. We recommend that you use the ‘auto’ cookie domain option in your tracker code, to make absolutely sure that Google Analytics will set the user-tracking browser browser cookie at the top level of your website’s domain so that it can be shared by all your subdomains. If you are hard-coding Google Analytics code on your site, use the ‘auto’ option for the cookieDomain field, by using the line:
ga('create', 'UA-XXXXXX-X', 'auto');
If you are using Google Tag Manager, the equivalent configuration in your Google Analytics tag is as follows:
Now your visitors will be recognised by Google Analytics as the same ‘user’ when they travel between your sub-domains.
Multiple Domains
Tracking the movement of visitors between separate domains that make up your site is a little harder. This would be where, for instance, you have both mysite.com and mysite.whitelabel-ecommerce.com all as part of the same website. To keep movement across these domains tracked by Google Analytics as a single user, you need to do some work to pass on to Google Analytics the client ID that it stores in the browser cookie for each site.
By far the easiest way to do this is to take advantage of a plugin that Google provide for Analytics, called ‘autoLink’. As you can probably guess from the name, it’s designed to solve a lot of your woes automatically, but you still have to set it up first.
With hard-coded Google Analytics tags, you first need to load the autoLink plugin and tell it which domains it is allowed to share your visitors’ identifying client ID. If you are working on www.mysite.com and want to allow client ID to be passed to mysite.whitelabel-ecommerce.com you would change your tracking code to something like this:
ga('create', 'UA-XXXXXX-X', 'auto', {'allowLinker': true}); ga('require', 'linker'); ga('linker:autoLink', ['mysite.whitelabel-ecommerce.com'] );
The first line gives permission to Google Analytics to share visitors’ client information and to accept client information passed to it, the second line loads the autoLink plugin and the third line tells the plugin which domains it may pass the client ID on to. Change the code on the whitelabel-ecommerce.com site in the same way, but specifying ‘www.mysite.com’ in the third line instead. The autoLink plugin will then automatically step in when your visitors click on links to the specified destination domain(s) and passes the client ID information in a query parameter that the Google Analytics code on the destination domain can pick up.
Using Google Tag Manager it is much easier. In your container on www.mysite.com, change your Google Analytics tag to add the following settings and change the tag on the mysite.whitelabel-ecommerce.com in the same way:
Republish your container and you’re done! Tip: you can modify the instructions above for additional domains, if you need them. In Google Tag Manager, just add extra domains under ‘Auto Link Domains’ in a comma-separated list; in hard-coded Google Analytics tags, add the extra domains to the array in the third line of code shown.
Referral exclusion
Finally, before you rest easy, you will want to make sure that Google Analytics recognises movement by people across your domains as a single session: after all, as we noted above, being attributed to the same client ID is only half of the solution. This part is the easiest of all. Just log into Google Analytics and go to the admin settings for your property and find your Referral Exclusion List settings:
Now all you need to do is add in all the domains that you want to treat as part of your website: mysite.com, mysite.whitelabel-ecommerce.com, etc. Don’t forget sites such as paypal.com or other payment processing engines which handle payments away from your main site: you don’t want Google Analytics attributing all your ecommerce sales to your payment processor just because your visitors return from their payment to a thank-you page on your site!
Phew
Congratulations! Your cross-domain tracking and self-referral issues should now be at an end. We’d love to hear how you got on or about any tricky issues you encountered in the comments below.
Comments