Solving Google Analytics Self-Referral Issues

IMPORTANT: This is a historical post from 9 October 2012.

If your website spans multiple domains or sub-domains, you might see your own website within the Google Analytics referrals reports. This is called self-referrals and generally indicates that you need to adjust your tracking code to correctly track visitors as they travel between your domains.

self-referrals
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.

self-referrals-landing-page

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

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:

  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:

  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:

  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 Google Analytics asynchronous (‘async’) tracking code.



  • http://www.blogger.com/profile/00039954951702526392 dan barker

    Thanks for the post.

    A 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.

    • http://www.blogger.com/profile/10418367156722243152 Benjamin Mangold

      Thanks for the comment Dan,

      We 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.

  • http://www.blogger.com/profile/04796454833090219439 Elmer

    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.
    Google Analytics

  • http://www.blogger.com/profile/13377002594356107210 Van Nes

    This comment has been removed by a blog administrator.

  • http://www.blogger.com/profile/13377002594356107210 Van Nes

    Hello Ben.
    I’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

  • http://zin.hu/ EdgarPE

    I have the same problem as Van Nes.
    I 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.

  • http://indianapolisseofirm.com/web-design/indianapolis-web-development-overview Alwin Mayer

    While it seems like a minor bit, it’s still annoying when you encounter this, especially when you’re a marketer trying to beat a tight reporting deadline and omitting unrelated items will be detrimental. This will be helpful to avoid such instances in the future.

  • http://www.blogger.com/profile/17616484144396658145 Unknown

    Setting up correct tracking for cross-domain or cross-subdomain, as descrbied above, will make it so the same cookie is used to identify the user across the different sites. It will NOT however, solve the problem of self-referrals- you must use addIgnoredRef for this. See #3 at http://www.roirevolution.com/blog/2011/01/google_analytics_subdomain_tracking.php

  • http://www.niekos.net/ Niek

    Hi, i still got the same issue!
    We implemented this code:
    [‘_require’, ‘inpage_linkid’, pluginUrl],
    [‘_setAccount’, ‘UA-XXXXXX-1′],
    [‘_setDomainName’, ‘domain.com’],
    [‘_setAllowLinker’, true]

    on both subdomains but still we see its as refferal traffic…

    any idea/

  • http://www.blogger.com/profile/14161293842370485753 Global Leadership Adventures

    What about www and non-www. how do I fix that?

  • http://www.blogger.com/profile/14161293842370485753 Global Leadership Adventures

    What about www versus non-www

  • http://alossra.blogspot.com/2013/03/2013-zuma-online-2013.html لعبة زوما

    While it seems like a minor bit, it’s still annoying when you encounter this, especially when you’re a marketer trying to beat a tight reporting deadline and omitting unrelated items will be detrimental. This will be helpful to avoid such instances in the future.

  • http://www.blogger.com/profile/05313581097341040207 Loves Data

    Hi Global Leadership Adventures,

    There are a lot of different issues that can crop up with cross domain tracking and tracking of subdomains. Here is a Google support page that addresses a number of these issues. Be aware that this information only applies to the ga.js tracking method.

    https://support.google.com/analytics/answer/3198398?hl=en

    Please let us know if you still have issues after going through these solutions.

  • Anonymous

    Just use this command in your tracking code

    _gaq.push([‘_addIgnoredRef’,’yourdomain.com’]);

    • http://www.blogger.com/profile/10418367156722243152 Benjamin Mangold

      This is an option, but it doesn’t actually fix the issue, instead it simply means self-referrals would be reported as direct traffic.

  • Dota

    Is there an update to universal analytics for this topic?