
If you have already modified your code for cross-domain tracking and you still receive self-referral traffic, some of your pages are likely missing tracking code or your cross-domain tracking code is not correctly installed.
Let's look at how your tracking code needs to be setup to remove self-referral issues from your Google Analytics reports.
The Problem
With self-referral traffic you lose conversion attribution. For instance, when a visitor comes from an advertisement, travels to a subdomain of your site and completes a goal, a self-referral will incorrectly attribute how the visitor arrived to your website. This makes proper analysis difficult.
This occurs because when a visitor travels between domains (or subdomains) without the proper tracking code, a new session is tracked by Google Analytics. This will also inflate your visit numbers inside your reports.
Solving Self-Referral Issues with Cross-Domain Tracking
In order to properly track visitors you need to ensure your tracking code is correct. We will look at two common scenarios, first, we will look at tracking visitors across multiple domains and then we will look at tracking visitors across different sub-domains.
Multiple Domains
One of the ways to examine which pages are missing tracking code is to log into Google Analytics and navigate to Traffic Sources > Sources > Referrals. Then enter your site URL in the search box. If your website appears in the results, you have a self-referral. Click on it and select 'Landing Page' as a 'Secondary Dimension'. Now you should be able to see which pages your self-referrals are coming from in the 'Landing Page' column.
To properly track visitors traveling from www.mysite.com to www.othersite.com, you need to make modifications to the tracking code on both sites. Basically, you need to transfer the cookies from one site to the other when a visitor travels between the domains. This helps to maintain the correct cookies and visitor information on all the domains.
In order to transfer the cookies, you need to make modifications to all the links directing people to other domain. For example, if a visitor is on www.mysite.com and clicks on a 'Buy now' link that directs to www.othersite.com, you will need to modify links appropriately:
<a href="http://www.othersite.com/checkout.html" onclick="_gaq.push(['_link', this.href]);return false;" > Buy now</a>
If the visitor can travel from www.mysite.com to www.othersite.com using a form, then the form code on www.mysite.com, needs to look like this:
<form action="http://www.othersite.com/form.php" method="post" onsubmit="_gaq.push(['_linkByPost', this]);"> etc...
Tracking code on www.mysite.com:
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-123456-1']); _gaq.push(['_setDomainName', 'mysite.com']); _gaq.push(['_setAllowLinker', true]); _gaq.push(['_trackPageview']); etc...
Tracking code on www.othersite.com:<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-123456-1']); _gaq.push(['_setDomainName', 'othersite.com']); _gaq.push(['_setAllowLinker', true]); _gaq.push(['_trackPageview']); etc...
Multiple Sub-Domains
If your website uses multiple sub-domains (e.g. http://www.mysite.com, http://news.mysite.com, http://promo.mysite.com, etc.) and your visitors move between them, different tracking cookies will be created on each subdomain. This means a visitor will not be recognised as the same visitor traveling between sub-domains and the main domain.
To fix this issue, a tracking code (like the one below) should be placed on the main domain and all sub-domains:
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-123456-1']); _gaq.push(['_setDomainName', 'mysite.com']); _gaq.push(['_trackPageview']); etc...
The _setDomainName() function defines which domains you should enable cookie access for any sub-domain.
The links to and from the main domain to the sub-domains do not need changes because the sub-domains are now setup to share the same cookies.
Once you have proper tracking code on all domains and sub-domains, your Google Analytics account will accurately track bounce rates, visits and attribution.
NOTE: The sample code provided in this article uses the latest Google Analytics asynchronous ('async') tracking code.


Thanks for the post.
ReplyDeleteA little caveat that may/may not be useful is that sometimes I see this where cross-domain tracking isn't the best option.
An example that seems to crop up fairly frequently is "m." mobile sites (where a visit from the "www." to the "m." looks like a self-referral). Sometimes there the most useful solution is to separate out the "m." traffic from the main profile entirely, treating them as separateish sites, and allowing to see where they refer to each other.
Thanks for the comment Dan,
DeleteWe would generally recommend going with the same code on the mobile and non-mobile versions of the site and then use advanced segments and/or filtered profiles to then perform analysis and reporting.
Using filtered profiles you could have the following profiles;
1) 'Mobile and Non-Mobile'
2) 'Mobile Only'
3) 'Non-Mobile Only'
If you also add the hostname (domain) into the pages report using an advanced filter you can even use the Visitor Flow report to understand visitor navigation.
Your article was nice. Thanks for sharing such important information that is commonly seen nowadays. Also, you've put some insights on how to solve that problem.
ReplyDeleteGoogle Analytics
This comment has been removed by a blog administrator.
ReplyDeleteHello Ben.
ReplyDeleteI'm using the _setDomainName parameter, but still see our seb-domain as a referral source. here is the code i use (i've copied it and replaced the private info):
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_setDomainName', 'mysite.ru']);
_gaq.push(['_addOrganic', 'nova.rambler.ru', 'query']);
_gaq.push(['_addOrganic', 'go.mail.ru', 'q']);
_gaq.push(['_addOrganic', 'nigma.ru', 's']);
_gaq.push(['_addOrganic', 'webalta.ru', 'q']);
_gaq.push(['_addOrganic', 'aport.ru', 'r']);
_gaq.push(['_addOrganic', 'poisk.ru', 'text']);
_gaq.push(['_addOrganic', 'quintura.ru', 'request']);
_gaq.push(['_addOrganic', 'search.qip.ru', 'query']);
_gaq.push(['_addOrganic', 'images.yandex.ru', 'q', true]);
_gaq.push(['_addOrganic', 'blogs.yandex.ru', 'text', true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
Do you have any suggestions of why this could happen?
Some possible problems are described here - http://www.roirevolution.com/blog/2011/01/google_analytics_subdomain_tracking.php
I have the same problem as Van Nes.
ReplyDeleteI use the _setDomainName and still see subdomains as referrals. My tracking code is as simple as possible, I just generated it on GA and copy pasted it to the site.
Every subdomain contains the tracking code, it's impossible to left it out, because of the CMS system.