Some time ago I blogged about using cross domain tracking in Google Analytics, but the processes used in Analytics have changed slightly since then. This blog provides an update on how you need to track your traffic if your website runs on a main domain with a sub domain and/or a third party domain name.
This blog is aimed at the person within your organisation who can implement code onto your website, as this is a technical guide to setting up and tracking websites with more than one domain name. Generally your web developer can help you with the implementation of this code, but should you need assistance, we include Google Analytics configuration with our services here at Vertical Leap.
Why do I need Cross domain tracking?
Cross domain tracking is used in Google Analytics when you wish to record the visitor information on a website which has more than one domain name. For example, if you run a blog on a sub domain and have a third party checkout website, you would track www.yourdomain.co.uk as the main site, http://blog.yourdomain.co.uk on a sub domain as the blog URL and www.yourthridpartycheckout.co.uk as a third party check out URL. You will need to use Cross Domain tracking on all three sites to allow Google Analytics to track your information correctly.
Code for your main site and any sub domains
To track across multiple domains you need to add two lines of code to the original tracking code for your website – this will allow the site to be tracked across all the domains and sub domains you use. On each site the code you use will be slightly different.
The two lines of code we are adding are the setDomainName and setAllowLinker line, which create the ability to keep the Google Analytics cookie alive and tell Google which domain names you are expecting to track.
On your main site and any sub domains you will add the code as below:
var _gaq = _gaq || ;
Code for a third party domain
On the third party domain name again you need to setDomainName and setAllowLinker lines into the code.
Remember also to use the same setAccount Number (which is the UA- number which I’ve represented with Xs in the above examples). If you use different account numbers your visitors will not be tracked correctly.
Your code would then look like this:
var _gaq = _gaq || ;
The importance of links
When you are linking between your main site and the third party site (so from www.yourdomain.co.uk or http://blog.yourdomain.co.uk to www.yourthridpartycheckout.co.uk) you have to add some Google Analytics tracking code to each of the link codes.
If you have a link which is part of a form you need to do this by adding the code below:
<form name=”f” method=”post” onsubmit=”_gaq.push(['_linkByPost', this]);”>
If you are not using a form then your link should be coded as per:
<a href=”http://www.yourthridpartycheckout.co.uk” onclick=”_gaq.push(['_link', 'http://www.yourthridpartycheckout.co.uk']); return false;”> checkout</a>
The URLs you use in the above code must be the URLs of the pages you are linking to.
Once someone is on the third party site you must also link using this code back to the main site or sub domain.
It is important that you follow this linking process as if you don’t add this link code you will not be able to see all of the information about visitor behaviour on your website.
You will find that visitors moving across the domain names will create traffic sources of your own domain name – this means that you will see your conversions or sales as coming from your own website and won’t be able to report on the effectiveness of your SEO, PPC or email marketing activities.
This is because the link code above tells Google Analytics to keep the visitor session open and to track the person as one session.
You do not need to do this if you are linking from the main domain to a sub domain (so from www.yourdomain.co.uk to http://blog.yourdomain.co.uk and back again) as these are treated as the same site as long as you have the setDomainName line in your tracking codes.
Once you have all this code in place you will be able to track your visitors across all the domains you have.