Blast Analytics and Marketing

Analytics Blog

Supporting Leaders to EVOLVE

Cross Domain Tracking in Google Analytics

February 1, 2011

Cross Domain Tracking Overview

UPDATE: The recommended way that cross-domain tracking is performed has changed since this post was originally written. Google Analytics code no longer enforces the domain hash, so you no longer have to use _gaq.push([‘_setAllowHash’, false]);

Cross domain tracking is required anytime you want to track a single GA session between multiple domains that you control.

A common example is a 3rd party checkout system that resides on a different domain. For the purpose of keeping our examples consistent throughout this blog post, let’s fictitiously assume that your scenario involves your primary domain ( and a 3rd party checkout provider (

Additionally, all code referenced in this document is using the asynchronous syntax. It is important to note that if you have not yet migrated over to the asynchronous format that the example code provided will not work as is.

Note: If you can get your provider to place their system as an alias onto a subdomain of your regular domain, this simplifies the setup process immensely. Also, users won’t look at the URL in their browser and wonder what site they are on (especially in cases where you can’t control the look & feel).

Impact of Not Using Cross Domain Tracking

If you don’t use cross-domain tracking or you have it improperly configured, you’ll end up with meaningless data that shows self-referrers in the visit reports and a lack of proper attribution towards your conversion points. As a visitor moves from your primary domain to the other, they will start a brand new session in Google Analytics.

To understand why this happens, you must first understand how Google Analytics works. Google Analytics uses first-party cookies that are attached to the visitor’s browser. Those cookies contain data about when the visitor last visited the site, what page it was, and a variety of other data. When the user clicks between pages or comes back at a later date, the ga.js javascript looks for the existence of that first party cookie. If it doesn’t find a cookie, then it views that visitor as a brand new visitor (that has NEVER been to your site). First party cookies are great (the best type), but for security reasons, they do not transfer between domains. The first party cookie is linked directly to the domain that set it and will not be accessible by any other domain.

If the visitor views a few pages on and then clicks a link or submits a form that takes them to, the ga.js script looks for a first party cookie tied to Without having cross-domain tracking properly configured, it will not find a cookie and will start a brand new GA visit as a new visitor. Now, of course, if you’ve had this problem for a while, you’ll see returning visitors because they’ve visited the in the past.

As you can see, this is a HUGE problem. If a visitor clicks an ad or performs and organic search and ends up viewing a page on the after viewing pages on, you lose ALL data about how that user arrived and the complete picture of what they did. If they end up converting, you will only know that they came from (which is not helpful at all).

Solution for Cross Domain Tracking

To properly track a visitor as they move from to, you will need to make code modifications to the code on both sites.

Steps & Code for

  1. On all pages of the site, set _setAllowLinker to true via _gaq.push([‘_setAllowLinker’, true]);
    This enables domain linking and allows the use of _link() and _linkByPost().
  2. On all pages of the site, turn off domain hashing via _gaq.push([‘_setAllowHash’, false]);
    Domain hashing needs to be turned off to allow the cookie to be properly read by the ga.js script.
  3. On all pages of the site, set the current domain name via _gaq.push([‘_setDomainName’, ‘’]);
    Note that there is a leading ‘.’
  4. Send the current GA cookies over to the domain via parameters in the link. Google makes this quite easy by using either _link() or _linkByPost() functions in your code. Both will transfer the cookies from one domain to the querystring of the resulting link. The ga.js script on the other domain landing page will detect the parameters in the URL and assemble a new GA cookie that references the same browsing session.

Here’s the full tracking code snippet along with an example link and form that pushes the GA cookies over to the other domain:

[code lang=”js”]<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-9999999-9’]);
_gaq.push([‘_setAllowLinker’, true]);
_gaq.push([‘_setDomainName’, ‘’]);
_gaq.push([‘_setAllowHash’, false]);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);


<a href=”” onclick=”_gaq.push([‘_link’, this.href]);return false;”>Checkout Now!</a>

<form name=”formName” method=”post” onsubmit=”_gaq.push([‘_linkByPost’, this]);”>

Steps & Code for

  1. On all pages of the site, set _setAllowLinker to true via _gaq.push([‘_setAllowLinker’, true]);
  2. On all pages of the site, set _setDomainName to ‘none’ via _gaq.push([‘_setDomainName’, ‘none’]);
    Note: When you use none as the domain name, it automatically turns off domain hashing.
  3. Use _link() and _linkByPost() to send GA cookies back to the if links exist to bring the user back. This is especially important if the initial landing page can be on the domain.

Here’s the full tracking code snippet along with an example link and form that pushes the GA cookies over to the other domain:

[code lang=”js”]<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-9999999-9’]);
_gaq.push([‘_setAllowLinker’, true]);
_gaq.push([‘_setDomainName’, ‘none’]);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);


<a href=”” onclick=”_gaq.push([‘_link’, this.href]);return false;”>Continue Shopping</a>

<form name=”formName” method=”post” onsubmit=”_gaq.push([‘_linkByPost’, this]);”>



If properly setup, cross domain tracking will maintain the proper referral and other session data for visitors on your site. You will begin to accurately track bounce rates, conversion sources, and other metrics.

The example code we’ve provided satisfies the most common cross-domain setup. There are specific circumstances and many variables that warrant different code and strategy.

Whether you need Google Analytics Help to check to ensure that the code you have in place is working correctly or you need help setting up tracking in another situation, we can help. Give us a call at 1(888)252-7866.

  • Pingback: Tweets that mention Cross Domain Tracking in Google Analytics | Blast Advanced Media --

  • Breklin

    Thank you for this very clear and useful demo. Quick question, though. Are the GA profile IDs supposed to be the same for the secondary domain as they are for the first? That is where I am stuck.

    • Great; glad you enjoyed the article! Yes, the GA UA-# should be the same for both the primary and secondary domain.

      • SoccerZortz

        I don’t see how you can set the GA UA-# the same on both sites. Currently, we have a different UA-# on the secondary domain. If I change that one to be the same as the primary domain, isn’t it going to break everything for the Google property we have set up for the secondary domain? Thanks in advance.

    • Hello Breklin,

      What I usually do is setup a profile per domain and filter just that domain traffic by applying a filter (custom filter: Include Hostname I use the same GATC on all domains (multiple top-level domains).
      On an aditional profile you can gather all domains traffic by not applying any filter. Don’t forget to call the _link() method when linking between domains, otherwise you will get wrong visitors and referrals data.

  • Keithnoone23

    Looks like an excellent post. Well laid out and easy to understand. I am going to give this a shot. Wish me luck!

  • Keithnoone23

    Ok so I tried but it didnt work fully. The query parameters werent being passed. I was looking at the google conversion videos and they said to do this?

    var _gaq = _gaq || [];
    _gaq.push([‘_setAccount’, ‘UA-21687229-1’]);
    _gaq.push([‘_setDomainName’, ‘none’]);
    _gaq.push([‘_setAllowLInker’, true]);

    Also I am linking through links that have an image I am trying:

    title=”click for the shop”>

    Any help with this is much appreciated.

    • Hi Keith,

      Change _setAllowLInker to _setAllowLinker (lowercase i).

      If you reply with your URL or email joe at with the URL, I will be happy to take a look at your implementation and advise further.

      If you use the onclick=”_gaq.push([‘_link’,this.href]);return false;” and there is an href value on the link tag that surrounds the image, it should correctly pass the parameters.


  • Hi Joe,

    There are some improvements that can be made to your code sample.

        var _gaq = _gaq || [];
        _gaq.push([‘_setAccount’, ‘UA-9999999-9’]);
        _gaq.push([‘_setAllowLinker’, true]);
        _gaq.push([‘_setDomainName’, ‘’]); //unnessary
        _gaq.push([‘_setAllowHash’, false]);

    Checkout Now!

    1). There is no need to invoke _setDomainName. Your post is ab
    out cross domain tracking, not subdomain tracking. The cookies will automatically write to the domain they are on.

    2). If one does call _setDomainName, then the leading period is not necessary. It is only required to track sub-subdomains. (
    Just a side note).

    **On the 3rd party site:

        var _gaq = _gaq || [];
        _gaq.push([‘_setAccount’, ‘UA-9999999-9’]);
        _gaq.push([‘_setAllowLinker’, true]);
        _gaq.push([‘_setDomainName’, ‘none’]); // use _setAllowHash to false instead
    Continue Shopping
    1). Here too, the call to _setDomainName should really be to _setAllowHash. While _setDomainName to none does indeed turn of domain hashing, it also writes the cookies to the explicit domain name. It is better to simply turn off domain hashing with _setAllowHash. _setDomainName doesn’t have any purpose for cross-domain tracking.Best,Yehoshua

  •    _gaq.push([‘_setAllowHash’, false]); has been deprecated

  • Michael

    How am I supposed to push the Analytics cookies over to the 3rd party page if the 3rd party page is displayed within an iframe?

  • Gabe Kassel

    this is great – way better than google’s own documentation

    i’m struggling on the profile setup side. i made two profiles with filters to filter out traffic on each others domain (site + 3rd party ecommerce store) but all profiles (site, ecomm, default) all show 100% of the cumulative traffic….?

    a second question, how do i use cross-domain with multiple GA profiles? i have two sites that funnel into the same ecomm store, for example.


    •  Hi Gabe,

      It sounds like you may not be using a regular expression to filter against the hostname.  So becomes ^$ in the filter as a regular expression.  That is just a guess though as to the issue. 

      For your second question, you need to make it dynamic to only load a specific GA UA-# on the store.  Need more information on the setup/scenario though to advise further.


  • Cory

    Hi Joe,
    Great post.  I’ve been successful setting up cross-_sub_domain tracking like this:

    But I also do this: contains an iframe of a WordPress form from

    So, if someone clicks an ad in my Adwords campaign, they land on and fill out the form through the iframe on

    How do I best code to capture that conversion?

    Here’s what I have on

    _gaq.push([‘_setAccount’, ‘UA-999999999-1’]);_gaq.push([‘_setDomainName’, ‘’]);_gaq.push([‘_addIgnoredRef’, ‘’]);_gaq.push([‘_trackPageview’]); 

    You said to alter the iframe src above but I get lost on the Google “Tracking Across iFrames” instructions.  What else should I do?

    Where do I put this?
    _gaq.push(function() {
      var pageTracker = _gat._getTrackerByName();
      var iframe = document.getElementById(‘myIFrame’);
      iframe.src = pageTracker._getLinkerUrl(‘’);});

    Thank you!

    • Hi Cory,

      You’ll want to place your code that modifies the iframe.src either in a document ready function or immediately below the iframe tag (recommended). This should append the cross domain cookies onto the iframe.

      On both domains, you should use _gaq.push([‘_setAllowLinker’,true]); to enable cross-domain.

      To complicate things though, in IE the iframe won’t set any GA cookies, which is a big problem. To get around this, you’ll need to setup a privacy via P3P. There is a section in the doc that explains this.

      Hope that helps!

  • @3e465e0e74aa9aed70bf13057e0babad:disqus All sites should share the same GA tracking code configuration. To configure a filter, go to Admin > Profles > Filters and then add a filter. Here’s a screenshot if you only wanted to include

  • carmen

    Hi Joe,

    Awesome post. thanks for that. but im still not sure what to do in my case.
    I have one domain which sells items, but transcation will be on another domain so this would be no problem. but the domain sells items itselfs.

    what i need to have is the following: one google account with only traffic and sales from domain (including the sales passed to, an another account with only traffic and sales from (no sales passed from

    is this possible?

    thanks in advance,


    • @a1ec93106b58329b7590317215c24319:disqus It is possible assuming you have control of or is willing to work with you to accomplish this. It is tricky. At a high level, you’d have to cookie users coming in from to (based on referrer data) and then if that cookie exists, fire the proper GA tracking code. Otherwise, if a user came to from a non source, it would fire the standard GA tracking code on

  • @a02c1a76c8ac542744216845f9eb7d7a:disqus You no longer need to use the _setDomainName ‘none’.

  • In GA there would be two different sessions between the separate UA-#s. The GA cookies though would still transfer between which means that the original source data should be intact.

  • why do you use _gaq.push([‘_setDomainName’, ‘’]); on domain1? is it optional?

  • Hi Berrega,

    Code needs to be the same to maintain domain hash, present in GA cookie. Otherwise cookies will be invalid and GA would assume new visitors for every page.

  • nirzari

    What if the landing page already has its own parameter ? I tried it and got that the parameters from the code appended by . (dot) after the landing page’s own parameters. This results as a broken link. Please help asap.

  • Ewa

    There is no need to use _gaq.push([‘_setAllowHash’, false]); right now.

  • Anat

    Hi Joe, thanks for the great article!

    I am looking for a solution, I’m not sure GA cross-domain can help me with. Thought you might know…

    My software supplies a Javascript code snippet to blogs to create related posts content recommendations at the end of the article.

    I would like to use a 3rd party tracking tool, like GA, to track the number of pageviews my code is located on. I can’t use GA cross-domain, because I am afraid of creating conflicts with the tracking of my hosting page.

    Got any idea what service I should use?



  • This is probably the best explination on why and how to do this I’ve found. Of course if you want to use Goals or e-Commerce you have to do even more as I’m learning. In the iFramed content on the 3rd Party website you need to get them to push an event to the passed in cookie / Google analytics code. I’m looking for a good example of this, I may have to build one…

  • marzio

    Hi Joe,

    is there a procedure to accomplish the same thing using google tag manager? I’m trying to link my site to a 3rd party shopping cart but all i got is meaningless data like sales referrals from PayPal.


    • @disqus_57dWQxA4Ww:disqus This is an old post. The new way would be to leverage the Universal Analytics (technique explained in this post: // In GTM when you configure the tag, there is a Cross Domain Tracking section of settings under the ‘More settings’ area where you can put in your list of domain to auto-link.

      • marzio

        Hi Joe, thanks.

        I’ll try that.

        One last thing, in the referral exclusion list do i need also to exclude the payment processor AKA PayPal?

        Basically it works like this: > > >

        • @disqus_57dWQxA4Ww:disqus Yes, you should add paypal to the exclusion list in the GA admin.

Joe Christopher
About the Author

As Vice President, Analytics at Blast Analytics & Marketing, Joe leads a team of talented, analytics consultants responsible for helping clients understand and take action on their vast amounts of data, to continuously improve and EVOLVE their organizations. With 20 years of experience in analytics and digital marketing, Joe offers a high-level of knowledge and guidance to clients across all industries. He is an expert in all major analytics platforms including Google Analytics and Adobe Analytics, as well as various tag management systems such as Tealium and Adobe Launch. He also consults on data visualization, data governance, and data quality strategies. Having extensive expertise in many areas, has enabled Joe to become a well known thought leader and speak at industry events such as Tealium’s Digital Velocity series. Joe remains on the pulse of various information technology, programming languages, tools and services, keeping Blast and its clients on the leading edge.

Connect with Joe on LinkedIn. Joe Christopher has written on the Web Analytics Blog.

Ready To Do More With Your Data?

If you have questions or you’re ready to discuss how Blast can help you EVOLVE your organization, talk to an Analytics Consultant today.

Call 1 (888) 252-7866 or contact us below.