How Google Analytics Tracks Third-Party Domains

Time for another installment of how to set up Google Analytics the right way! Today we’re going to talk about how to configure GA if your website spans multiple domain names. This is often the case if you’re using a third party shopping card. Just a note, I’m not going to get into the actual installation steps in this post. I want this to be a conceptual. If you’re looking for step by step instructions you can contact me or find them on them here on the GA Support Site:

Before we get into the nuts and bolts of the setup, it’s important to understand the fundamentals of how GA tracks visitors. GA uses first party cookies to identify your site visitors. We all know what cookies are, right? First party cookies are set with the same domain name that is in the location bar of the visitor’s browser. It is very important to understand that cookies can only be ‘seen’, and changed, by the domain that sets them. In fact, it is almost impossible for a website to set a cookie for a different website. This is due to a default security setting that most browsers have. Website A can not set a cookie for website B.

Let’s take this knowledge and apply it to how GA works. When a user lands on a page in your site the urchin.js tracking code looks for the GA tracking cookies. If it finds the cookies then it updates them. If it does not find the cookies it sets them. Remember, if your website domain is, then the urchin.js tracking code can only recognize cookies with the domain and it can only set cookies for the domain.

As the user continues their session the urchin.js interacts with the tracking cookies. Continuing with our example, the user on our site is just about to click on a link to different domain, the third party e-commerce platform we use. They will leave our domain and go to the e-commerce provider’s domain. We’ve been tracking this user with a specific set of cookies on our domain. When the visitor leaves our domain we want them to take their cookies with them. The cookies identify them as a unique visitor, if they don’t take their cookies to the next domain then we will loose the rest of their session information and that’s not good.

So how do we transfer the cookies to the shopping cart site? With Google Analytics we can pass the cookie values to the shopping cart domain via the query string. There are two conditions that need to be met for this technique to work:

  1. We need to add the urchin.js tracking code to the pages on the third party domain (I’ll explain this in a second).
  2. The third party domain must permit us to pass data via the query string.

If the third party domain does not allow the above then you can NOT use GA to track your visitors on the shopping cart pages. Sorry, there’s no way around it, both conditions must be met.

Here’s how we normally configure GA to work with a third party site. We wrap the link (or form) that directs the user to the third party site in a JavaScript function. This function literally picks up the cookie values from the visitor’s computer, appends them to the URL and then forwards the user to the third party domain. Once the user arrives on the destination page the urchin.js pulls the cookie values from the URL and sets a new set of cookies with the values extracted from the URL. That’s why we need to add the urchin.js to the pages on the third-party site. We need the code in the JavaScript file to pull the values for the cookies from the URL. It’s really important to understand this last step because it overcomes the two hurdles we discussed above.

First, we’re transferring the visitor’s cookie values from one domain to another. This means that the entire visitor session will be captured. All the identifying information for the visitor stays with the visitor as they traverse the different domains.

Second, the GA tracking cookies on the third-party site will be first party cookies so they are less likely to be rejected by the browser.

We all know that getting the complete picture of a visitor’s session is vital to better understanding of the referring information and site configuration. I hope this post gives people a better idea of how GA is tracking their traffic across third-party domains so they can configure it correctly.

Be Sociable, Share!

    Like this post? Sign up to get posts delivered to your inbox.


    1. Ken Aston says

      Great article! Do you know if Google Adwords conversion tracking and cross-channel tracking use the same method, especially if these cookies are also first party cookies? Regards, Ken Aston

    2. Casey says

      Is there anyway to pass the session data to the ecommerce site via POST instead of GET / Query String. My ecommerce solution is Volusion. They don’t allow non alphanumerics to be present in the query string variables. That screws things up.

    3. says

      Will these query strings attach themselves to the cookies on a Paypal site. Have you had success tracking visitors from 1st domain to Paypal domain and back to thank-you page on 1st domain?

    4. says

      Hi Justin,

      It is possible to track AdWords conversions on a 3rd party domain without making any adjustments to the conversion tracking code. Just place the AdWords conversion tracker on the 3rd party domain and when a conversion is made it wil track automatically (3rd party cookie in as opposed to first party cookie with Google Analytics)

    5. says

      Hi Tim,

      Thanks for the comment. You’re absolutely correct, you can use AdWords conversion tracking to facilitate cross domain tracking. But I think there are 2 advantages to GA:

      1. Site data. AdWords only tracks conversions while GA will tell you about what people actually did on your site.

      2. First party cookies. Third party cookies are really becoming a thing of the past. With most browsers configured to block third party cookies it’s getting harder and harder to track sites with a third party tracking system.

      Thanks again for sharing your thoughts.


    6. VC says

      “the GA tracking cookies on the third-party site will be first party cookies”. I do not understand why the cookie created by the Javascript from the third-party domain can be considered as a first-party cookie, even if it contains the same data. Please can you explain?

    7. says


      GA always uses first part cookies. The reason why the cookies remain first party cookies, even on the third party domain, is the GA JS is also on the third party domain. The JS always creates a first party cookie, relative to the domain it is on.

      So, if I place the GA tracking code on 100 sites, it will create 100 first party cookies, one for each of the 100 sites.

      Hope that helps.


    8. says

      Hi Justin,

      I’m trying to set up a goal that will tell me if a visitor to my site clicks on a link to a third-party site (my on-line catalogue). That’s the extent of the feedback I require but I can’t seem to find a way to do it as I don’t have access to the coding of the third-party site. Any help would be appreciated. With thanks.

      Regards, Jonathan

      • says

        @ Jonathan: What you need to do is create a virtual pageview when someone clicks on the outbound link and then use that for a goal. Check out this post. It’s a bit old, but should give you some direction.

        Thanks for the question!

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>