Previously I explained what cross-domain tracking is and how it works. This post is more about the ‘how’ rather than the ‘what’ and ‘why’.
Cross-domain tracking using inline script
If you are not using GTM yet (what are you waiting for?!?!) and your GA tracking script is still hardcoded, it will look something like this:
In order to enable cross-domain tracking, you will need to modify your tracking script on your primary domain with these additional parameters:
For your secondary domain (in this case siteb.com) you will need to do the same, but here you need to replace the line ‘ga(‘linker:autoLink’, [‘siteb.com’] );’ with ‘ga(‘linker:autoLink’, [‘sitea.com’] );
If you have multiple domains, you can list the domains in a comma separated list: ga(‘linker:autoLink’, [‘siteb.com’, ‘sitec.com’] );
Now let us take a look at what we have just added to our tracking script.
‘allowLinker’:true is there to tell the script to look out for the _ga cookie values in the url and grab them when they are present, this by the way has no merit on sub-domain tracking. ga(‘require’, ‘linker’); loads the GA cross-domain plugin and ga(‘linker:autoLink’, [‘siteb.com’]); defines which domains to autoLink to.
Cross-Domain tracking using GTM
Using GTM, this process is very straightforward and quick to set up. Cross-domain tracking is set up using your Universal Analytics pageview tag. For this we need to look at the ‘More settings’ menu. Expanding this exposes a wealth of stuff we can tinker with. However for the purpose of setting up cross-domain tracking we will only focus on two of the 7 additional settings, these are ‘Fields to Set’ and ‘Cross-Domain Tracking’.
Within ‘Fields to Set’ we will add two fields. These are ‘allowLinker’ and ‘cookieDomain’. We are going to set our allowLinker to ‘true’ and let GA decide which is the best cookie domain to use by setting it to ‘auto’. Please see the below screenshot for reference.
Next we are going to take a look at ‘Cross-Domain Tracking’ further down the page. Here you will find 1 field that you need to fill out and two drop-down menus which are optional.
Similar to what you saw in the previous example with the script where we talked about ‘ga(‘linker:autoLink’, [‘siteb.com’] );’, we will be using the ‘Auto Link Domains’ field to tell our tag which domains we want to track as part of cross-domain. In the above screenshot I have stated that I want to maintain my original traffic source when navigating between sitea.com and siteb.com.
‘Use Hash as Delimiter’ dictates whether the cookie values shall be appended to the url using either a query string or a url fragment.
‘Use Hash as Delimiter’ set to ‘False:’
‘Use Hash as Delimiter’ set to ‘True’: http://www.siteb.com/#_ga=1.123456789.9876543210.123456789
Which one to use depends on a case by case basis. It really depends on how the website has been built. Query strings are used by default. If this breaks the site then use the url fragments. If neither work, you will need to liaise with the dev who has built the site in order to find a solution. Setting ‘Use Hash as Delimiter’ to true will not affect the usage of other url fragments or query strings.
‘Decorate Forms’ should be used when you have a form that does a cross-domain submission.
Once you have successfully configured your tag and tested it thoroughly, (especially on websites built on older platforms!) create a new version in GTM and publish the changes. The next thing you need to do is go into GA and add the second domain that you want to track to the referral exclusion list. This is found in the Admin section in the middle column under ‘Tracking Info > Referral Exclusion List’.
And this is how you implement cross-domain tracking. Using Google Tag Manager is definitely the quicker and easier option of the two. I hope this two parter helped you understand where, when and how to implement cross-domain tracking. If you get stuck or have any questions then don’t hesitate to get in touch.
394 Pacific Avenue, Floor 5
San Francisco, CA 94111