seo

Google Analytics Cross Domain Tracking Made Easy

A default Google Analytics implementation will break your visits when tracking cross domain websites (such as webshops using an external payment gateway) because the first-party cookies can only be read from the domain that set the cookies. When switching domains a new cookie is created and thus a new visit is registered. This could result in an incorrect report of the number of visits, but even worse, it could also strip the original referrer from your visits. All that hard work that has been put into optimizing your SEO and SEM campaigns goes down the drain when all conversions and transactions get attributed to your own website as a referrer.

This can easily be fixed by adding some additional lines to the Google Analytics tracking script and by adjusting all links and forms pointing between the domains. This procedure is well documented by Google Code. For relatively simple websites adjusting all links and forms is pretty easy, but as time passes and your website becomes more complex maintaining a correct implementation becomes harder. You might forget to adjust some links or someone adds a new form that doesn’t have the right adjustments. Luckily jQuery offers the ability to automatically adjust all links and forms pointing between the domains by including one script that can be used on all pages. To learn how jQuery works, how you can select specific DOM elements, and how you can apply functions, check out this jQuery documentation page.

Adjustments to pages on Domain A
If you haven’t done so already include the jQuery library within your page:

Adjust your Google Analytics tracking script by adding the following line:

_gaq.push([‘_setAllowLinker’, true]);

Your script will look like this and should be placed in your section:

Include the following jQuery script after the jQuery include and before the GA tracking script:

Adjustments to pages on Domain B
If you haven’t done so already include the jQuery library within your page:

Adjust your Google Analytics tracking script by adding the following line:

_gaq.push([‘_setAllowLinker’, true]);

Your script will look like this and should be placed in your section:

Include the following jQuery script after the jQuery include and before the GA tracking script:

You can test this by inspecting the url after clicking on any of the links or submitting any of the forms between the sites. You should notice a string of parameters appended to your url containing the cookie data from your originating domain. Google Analytics will process this url and recreate the cookie on the other domain causing the visit not to break and to keep the original referrer.

Related Articles

Leave a Reply

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

Back to top button