Tracking visits between your main domain and sub domain
Google Analytics is a great program to track visitors and content to your website, but by default Google Analytics can only track visits on a single domain or sub-domain. There are however many circumstances where you may wish to track visitors, between your main domain and sub-domain, they include:
- Shopping Cart – Your shopping cart maybe on a sub-domain, and you may wish to track traffic from your site into your shopping cart in one report profile. You may also want to set up goal tracking and funnels all in one profile.
- Blog – You may have a blog on a sub-domain – You would want to track traffic to and from the blog in the same profile
- Your site may use sub domains for site content instead of sub folders, and you want to track the traffic in one easy to manage profile
- Many other reasons…
If you don’t set up cross domain tracking your sub-domain account will produce lots of referrals from your main site, meaning that the original referrer such as Google will be lost. This means that potentially you are losing out on important data as to where your traffic is coming from when a users skips between your domains.
In order to track visitors between your main domain and sub-domains you will need to edit the tracking code that appears on both domains.
Lets suppose you want to track traffic between the www.mystore.com and cart.mystore.com. The tracking code to achieve this is indicated below:
Asynchronous syntax
1 2 3 4 | _gaq.push(['_setAccount', 'UA-12345-1']); _gaq.push(['_setDomainName', '.mystore.com']); _gaq.push(['_setAllowHash', false]); _gaq.push(['_trackPageview']); |
Traditional (ga.js) syntax
1 2 3 4 | var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._setDomainName(".mystore.com");
pageTracker._setAllowHash(false);
pageTracker._trackPageview(); |
You will notice that there is a leading “.” before the domain name, this indicates that you want to track any sub-domain of this main domain. It is important that you add this tracking code to all pages on the main domain and sub-domain in order to track everything successfully.












Leave your response!