Upcoming LunaMetrics Seminars
New York City, Aug 4-8 San Francisco, Aug 11-15 Los Angeles - Anaheim, Sep 8-12 Washington DC, Sep 22-26

Automatic Cross Domain Tracking

(Update: We have an automatic cross domain tracking script for the asynchronous version of Google Analytics. Check it out!)

Whenever a visitor crosses from one domain to another, the information contained in the cookies must be passed in the query string to the second domain. Google Analytics documentation recommends using the provided method of _link().  This looks like:

<a href=”http://www.newsite.com” onclick=”pageTracker._link(‘http://www.newsite.com’);return false;”>Go to our sister site</a>

Following this link will cause the visitor to arrive on the page http://www.newsite.com/?__utmb=. . . .&__utmv=. . . .&_utmk=123456789&__utma=1.1234567.1234567. . .&utmz=. . .

With the values of those query parameters used by the GA code on the new site to create the necessary tracking cookies.

But when you have a very large number of links that cross from one domain to the other, it is difficult to find and modify every one, and to continue to maintain and update new links as they are created in the site.

To manage a situation like this you can use JavaScript to automatically determine which links are cross-domain links.  Once the script has determined which links are cross-domain links, it can create event listeners to wait for someone to click on that link.  When they click, the event listener will trigger the GA code that adds the cookie information to the query parameters.

There are several examples of scripts like this, and sometimes the script will need to be modified slightly to suit a particular web site or particular needs.

iQ Content published an autotracking script in this blog post:

http://www.iqcontent.com/blog/2009/08/google-analytics-automatic-tracking-across-multiple-domains/

An example of a script that I used for a particular client:

http://lunametrics.com/autoTrack-crossdomain.js

You can also find script examples in the books:

* Advanced Web Metrics by Brian Clifton (http://www.advanced-web-metrics.com/blog/about-the-book/)
* GA Short Cuts by Justin Cutroni (http://gashortcut.com/)

If you have an example of an automatic tracking script for GA you’d like to share, link to it in the comments below.

http://www.lunametrics.com/blog/2010/02/04/automatic-cross-domain-tracking/

3 Responses to “Automatic Cross Domain Tracking”

John Daly says:

Is this to say I can track where that last user is coming from and use that as relevant information when monetizing?

John says:

Yes. Normally you can see this in GA by default in the Traffic Sources reports.

When the website crosses domains, and you want to know where they came from originally, and you want to treat more than one domain as a single website, then the sites need to implement cross domain tracking in order to see the original referrer information.

It is that implementation that this post talked about.

Chris says:

So I was looking at the differences in you script and Peter’s. I’m trying Peter’s route first, but I wondered why your code was so much more complex. If I’m following it correctly, you check first to see if it is a specific filetype, not really a link, then you check to see if its an external link. Now are you tracking external links too.
Is that the difference, you script also tracks downloads and external links?