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.

Cross Domain Tracking

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 }

Tips for Start Up SEO Agencies

November 19, 2011

Running an SEO agency is not an easy job. It is a very competitive landscape in terms of price and quality. Here are some tips that helped me roll my agency to great success. 1. Focus on Small  & Medium Business Having a very good experience of working in SEO agencies backed up by huge [...]

Read the full article →

Portable Skype on your USB Drive

October 13, 2011

If you are someone who loves to break the rules, here is something which is of your interest. Ever imagined of installing skype in a USB drive and carry to your work place or internet cafe where Skype is not installed? The newest version of Skype help you load it from a flash memory. You [...]

Read the full article →

Importing Google Analytics to your adwords account when you have 2 different accounts.

October 22, 2009

Google allows you to access Google Analytics from your Google Adwords account interface. You will see this option under “Reporting” tab in your Google Adwords account. To add your account follow the below steps: Make sure you in your Google Adwords Account Click on Reports tab in the the Top menu Click on Google Analytics. [...]

Read the full article →

Google Launches ‘Fetch as Googlebot’ and ‘Malware Details’ in Webmaster Tools Labs

October 14, 2009

Google launched two new features that help webmasters know more on how Google see your website. These two features are “Fetch as Googlebot” and “Malware Details.” As you may know, Google before doing an official release of any tools launches the application under the banner Google labs where they gather the customer experience to see the chances of improvisation. The two new features can be found under your webmaster tools under the banner Labs which comes next to “Diagnostics” in the left hand side menu.

Read the full article →

Google does not use the keywords meta tag in web ranking

September 24, 2009

Matt Cutts of Google Web Spam team explaining on whether Google consider Keyword Meta Tag  in ranking View more details on this on Google Webmaster Blog

Read the full article →

Things To Remember Before You Dive In For An Ecommerce Venture

September 17, 2009

Starting an online business is no more a tough job. Now we don’t have to depend on any ecommerce shopping cart company paying a huge some of monthly subscription fee or  run after the customer support in getting help on fixing bugs in their systems. Many open source shopping cart enabled ecommerce applications are available [...]

Read the full article →

Google’s Matt Cutts on WordPress Blogging

August 20, 2009

Matt is someone whom I love to follow. I am a fan of Matt Cutts Blog and this is one of his interesting video presentation available online. He talks about how Google see wordpress blogs and how bloggers can improve their bloggs by meeting Google Webmaster Guidelines. I am a wordpress blogger and it was [...]

Read the full article →

Google Analytics – What is it?

August 15, 2009

Importance of Web Analytics is increasing day by day as more websites of the same niche compete for a similar or unique goal. Webmasters now have access to lot of quantitative data that can help them find answers for all “What” on their website. What pages are visited, what products people buy, what browser they [...]

Read the full article →

Change of Address Feature in Google Webmaster Central

June 25, 2009

This entry was written for SEO Herald Blog . If you were using the Google webmaster tools for your website, you might have noticed a change in the outlook of the webmaster tools. The old interface was an option before few weeks and now Google have migrated all webmaster accounts to its new interface. The [...]

Read the full article →