Cross Domain Tracking – What It Is and How to Fix it
One of the most common tagging problem comes from cross domain tracking. In this post I explain why cross-domain tracking can be a problem, and what your options are to fix it.
What is cross-domain tracking?
Cross-domain tracking happens when a visitor to your site is taken to another domain or sub-domain, and you are interested in viewing that activity as one big session rather than multiple small ones. For example, let’s say you have a blog (myblog.com) and a sales page (mysalespage.com). The main purpose of your blog is to get organic and social media traffic. In your sidebar, there is a link to your sales page. A typical visit goes like this:
- John types on Google, “how to do this amazing stuff.”
- The first entry in the Google search result is a link to an article on myblog.com; John clicks on that link.
- John is taken to myblog.com, where he sees the sidebar banner “Buy the new How-to Do This Amazing Stuff in Just 10 Seconds!”
- John clicks on the banner and is taken to mysalespage.com.
- John happily purchases your e-book for only 20 payments of $99 each.
The result? For myblog.com, you see one visit with the traffic source = Organic/Google and Keywords = “how to do this amazing stuff.” For mysalespage.com, traffic source = Referral/myblog.com, Keyword = none. This collection of information doesn’t provide the critical information you need as a business owner: which traffic sources and keywords bring you money. The three most common situations where cross-domain tracking is needed involve:
- Using separate domains for your blog and your sales page/squeeze page.
- Using the default thank-you message hosted by your auto-responder.
- Using a default third-party shopping-cart configuration without using a thank-you page hosted by your website, or adding your Google Tracking code the the shopping cart pages).
What is the source of the problem caused by cross-domain tracking?
The problem with cross-domain tracking arises from the fact that Google Analytics uses first-party cookies.
Sorry, Cookie Monster—I’m not talking about THOSE cookies!
Cookies are small text documents used to store information about your current and past sessions on a website. All cookies are named using the domain (or sub-domain) name of the site that created them. A first-party cookie is a cookie created by the website itself. If you check your browser settings, you should have a cookie named simpleanalytics.net that was created by this site. When a new session is started on a site, Google Analytics checks to see if a cookie matching the domain (or sub-domain) exists. If it does, Google uses the information in the cookie to track the visit. If the cookie doesn’t exist, Google creates one, sets the visit as the first one, and records all the information it has available (including traffic source, browser type, location, etc). Since the cookie’s information can’t be shared—unless of course you used the cross-domain tracking code—the data collected in one domain is not available to the next one.
One more example: My sad story
The day I start selling my e-book, I was so excited that I made the following error:
|My sales pages
Traffic source : Organic /Google
Keyword : simple analytics
Track page view hell YES!
|My shopping cart
Traffic source : NA
Keyword : NA
Track page view NO!
Traffic source direct
Track page view YES!
While my purchase confirmation page was tagged with my Google Analytics tracking ID, the cookie created by e-junkie couldn’t access the traffic source information stored in my sales-page cookie (simpleanalytics.net) The result? My sales funnel looked like this:
How can you track multiple domains or sub-domains?
Solution 1: The best way to solve a problem is to avoid it!
If you can avoid cross-domain tracking by hosting all your web pages under the same domain, then do it. That’s not always possible, but you should at least try to host your squeeze page/sales page under the same domain as the thank-you page or receipt page. Whenever you have the option to host your own thank-you page, do it! It will look more personal and you will be sure that your Google Analytics tracking code is there. In this case, the cross-domain tracking code is not required.
The basic PayPal shopping cart doesn’t let you add your own Google Analytics tracking code. In this case, you need to redirect buyers to a thank-you page located under the same domain as your sales page.
NOTE: Some people claim that you need to add the parameter ?utm_nooverride=1 to avoid overwriting the traffic source to PayPal instead of the real traffic source. In my last implementation, I didn’t use the parameter, and the traffic source was not changed to PayPal, so I don’t think this parameter is required.
If you structure your funnel in this way, so that it goes your sales pages -> PayPal -> your hosted thank-you page, you don’t need cross-domain tracking at all! Your code on both your sales page and thank-you page will look like this:
Solution 2: Use a cross-domain tracking code.
Sometimes you can’t host your blog, sales pages, and thank-you page under the same domain or sub-domain. In this case, you will have to use cross-domain tracking to pass the cookie information from one site to the other using either the link() method or the linkByPost() method and a cross-domain tracking code. If you feel overwhelmed, don’t worry—the Yoast plugin can do all this for you. You can also refer to the Google Analytics documentation for help.
But this is important: To make it work, you have to use the SAME Google Analytics ID on every single domain/sub-domain you want to track. If you fail to do this, it won’t work.
Case 1: Tracking a domain and subdomain
This one is the easiest. Let’s say you have your main website at www.myblog.com and your shopping cart at shop.myblog.com. The only thing you need to do is add _gaq.push([‘_setDomainName’, ‘myblog.com’]); to your tracking code. Then use the following tracking code on both myblog.com and shop.myblog.com:
<script> var _gaq = _gaq || ; _gaq.push(['_setAccount', 'UA-12345-1']); _gaq.push(['_setDomainName', 'example-petstore.com']); _gaq.push(['_trackPageview']); </script>
By using the function _setDomainName, you are telling Google Analytics to use the same cookie for both domain and sub-domain. Since both sites will then be reading the same cookie, there is no need to send cookie information using the link() method.
Case 2: Tracking two top domains
If your blog is at www.myblog.com and your shopping cart or squeeze page is at www.mymoneypage.com, you will have to do two things to ensure tracking is done properly:
1. Change your Google Analytics scripts for www.myblog.com to this:
<script> var _gaq = _gaq || ; _gaq.push(['_setAccount', 'UA-12345-1']); _gaq.push(['_setDomainName', 'myblog.com']); _gaq.push(['_setAllowLinker', true]); _gaq.push(['_trackPageview']); </script>
And for www.mymoneypage.com to this:
<script> var _gaq = _gaq || ; _gaq.push(['_setAccount', 'UA-12345-1']); _gaq.push(['_setDomainName', 'mymoneypage.com']); _gaq.push(['_setAllowLinker', true]); _gaq.push(['_trackPageview']); </script>
Please note that I am using the same tracking id on both domains (UA-12345-1), that I am using the _setDomainName in case we also need to track subdomains (e.g., shop.mymoneypage.com), and that I am using _setAllowLinker. This function tells Google Analytics to use the cookie information stored in the URL parameter when the link() or linkByPost() is used.
2. Change ALL your links pointing both ways between your top domains with link() or linkByPost(). If you have a link from www.myblog.com to www.mymonpage.com your link should look like this:
<a href="http://www.mymoneypage.com"> Buy My Stuff</a>
You will have to change it to look like this:
<a href=”http://www.mymoneypage.com” onclick=”_gaq.push([‘_link’, ‘http://www.mymoneypage.com’]); return false;”> Buy My Stuff</a>
Once all this code is in place, the link to your mymoneypage.com should look like this in the browser :
If you don’t see such a long ugly link, it is not working! All the parameters are in the cookie information stored by www.myblog.com. The setAllowLinker() function will tell Google Analytics to use those parameters to build the cookie instead of creating a new one from scratch.
Tagging each link manually—Are you loco?
A few years ago, you would have had to code each link manually. Thanks to the Yoast Google Analytics plugin, this complicated job can now be done in about 10 minutes. See this video to learn how:
Oh! Did I mention that you should always host your own thank-you page under the same domain as your squeeze/sales page?
I know, this is complicated—but remember the real power is in the traffic source information, and without cross-domain tracking this information is lost. Leave your questions in the comment, if you have any.
Latest posts by Marcos D'Urbano (see all)
- Why you should use advanced segments in Google Analytics - March 22, 2016
- Finding SEO opportunities with Google Analytics - November 26, 2014
- How to Track Goal with Google Analytics - January 23, 2014