Over the past year I came across lot of people seeking help in Cross Domain Tracking using Google Analytics. Most of the people think its the most difficult job in Analytics. It is not. Its very simple if you understand few basic code changes to the standard Analytics Tracking Code. To those who don’t know what is cross domain tracking, I can explain it with a diagram here.
Say for example, you are on an ecommerce website trying to purchase something. Let us call that website www.yourdomain.com. You select your favorite product from the page yourdomain.com/product and add it to the shopping cart. Now you are redirected to the shopping cart which is hosted in a 3rd party domain for example www.someshoppingcart.com. You complete the order in that website and after completion you are taken back to www.yourdomain.com/thank-you-for-your-order.php
In this case you will find it difficult to transfer the visitor information from one domain to another. Here is when you need to implement Google Analytics Cross domain tracking.
When it comes to tracking a single domain, it is very simple. You just need to insert the Google Analytics Tracking code to the <head> tag of all the pages which you need to track. The standard code looks like this
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_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);
})();</script>
NOTE: You need to replace UA-12345-1 with your Google Analytics Account ID
Cross Domain Tracking Code Modification
You need to customize the code on both the websites.
1. Tracking code for Yourdomain.com will be -
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-6']);
_gaq.push(['_setDomainName', 'yourdomain.com']);
_gaq.push(['_setAllowLinker, 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);
})();</script>
NOTE: You need to replace UA-12345-1 with your Google Analytics Account ID
You need to add the above code to all the pages of your domain1. You will also need to modify the code on the shopping cart link to something like this -
<a href=”http://someshoppingcart.com/add-to-cart” onclick=”_gaq.push(['_link', 'http://someshoppingcart.com']); return false;”>Add to Cart</a>
Make sure to place the full URL you’re linking to in the onClick tag.
2. Tracking code for Someshoppingcart.com will be -
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-6']);
_gaq.push(['_setDomainName', 'someshoppingcart.com']);
_gaq.push(['_setAllowLinker, 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);
})();</script>
NOTE: You need to replace UA-12345-1 with your Google Analytics Account ID
You need to add the above code to all the pages of your someshoppingcart.com. You will also need to modify the code on the shopping cart link to something like this -
<a href=”http://yourdomain.com/thank-you-for-your-order” onclick=”_gaq.push(['_link', 'http://yourdomain.com']); return false;”>Confirm Order</a>
Make sure to place the full URL you’re linking to in the onClick tag.
Doing this will transfer the visitor cookie information between the domains. And by this way you will know the visitor source/medium/keyword details.
{ 1 comment }








