This post is not about setting up cross-domain tracking for Google Analytics but let’s have a quick reminder on what it is and how to set it up.
Cross-domain tracking is basically adjusting the GA settings to be able to aggregate traffic on domainA.com and domainB.com in the same GA property. This is done by allowing the _ga cookie to be shared between these domains. To do this we need to:
- Append the _ga linker parameter to the destination URL when coming from the origin domain – and vice versa. The _ga linker parameter looks like _ga=1.199239214.1624002396.1440697407 and consists in the GA client id + timestamp + some other special ingredients…It should be generated and appended (automatically with the autoLink method or manually) to the destination URL just before the user gets redirected to the destination URL to prevent any issues related to links sharing. More information on the linker here;
- Set the allowLinker field to ‘true’ to tell GA to parse the _ga linker parameter;
- Set the cookieDomain to ‘auto’ (this should already be the case);
- Add the domains (domainA.com, domainB.com) in the Referral Exclusion List in your GA property settings.
See here for a simple description on how to do this in GTM.
So, to my knowledge, having this _ga linker in the destination URL is the sine qua non condition for your cross-domain tracking to work. No other way around.
Which brings us to the quite simple solution explained below to monitor when this is broken. Yes, even if you initially set it up correctly, cross-domain tracking can be broken for many reasons: an update to the site preventing the autoLink method from working, a redirection or a server-side setting stripping out the _ga linker parameter, etc. And when it’s broken, this is vicious enough for you to notice that only weeks after it actually broke. You would basically see an increase in sessions (as a new session would start when landing on domainB.com from domainA.com) and in sessions attributed to Direct.
So, to be aware on the day (or the day after) it happens, you can setup the following solution, which requires GTM and consists in:
- Sending an event to GA when the Page URL is on domainB.com (or domainA.com) and the referrer is domainA.com (or domainB.com) and the Page URL doesn’t contains the _ga linker parameter;
- Setting up a custom alert in GA to let you know if this event has been sent.
To do this we need:
- A variable for the _ga Linker URL Query
- A trigger per domains to track (2 in my example)
- A GA event tag
- A GA custom alert
1- Create the gaLinker Variable
Go to the variable section in GTM and create the URL type variable as below:
You also need to enable the in-built Referrer and Page URL variables if not already done.
2- Create the Google Analytics Event Tag
I’ve added the built-in variables Referrer and Page URL for the event label so I can quickly see where the issue is coming from.
I’ve also chosen to set this event as a non-interaction hit so it doesn’t impact the bounce rate.
3- Create the Triggers
In this example, we have 2 triggers:
– one for broken cross-domain tracking from domainA.com to domainB.com
– one for broken cross-domain tracking from domainB.com to domainA.com
If you have a third domain, then you’ll need 3 triggers:
– one for broken cross-domain tracking from domainA.com or domainC.com to domainB.com
– one for broken cross-domain tracking from domainB.com or domainC.com to domainA.com
– one for broken cross-domain tracking from domainA.com or domainB.com to domainC.com
The triggers basically check that:
- The referrer is domainA.com (or domainB.com);
- The destination URL is domainB.com (or domainA.com);
- The _ga linker parameter is not defined in the destination URL.
The entire tag configuration should look like below:
4 – Create the Custom Alert in GA
Now that we have setup this event, we need to create a custom alert in GA so we can receive an email when this event is reported.
So, go to the GA View settings and click on Custom Alerts:
Then create the daily alert like below:
And that’s it.
Hopefully you won’t receive any of those but if you do, you’ll know it and fix it faster!