Copying Google to Record Client IDs
In the Data Science and Advanced Analytics team, we’re a little bit obsessed by user identification in our projects. It’s because the better we’re able to track users across devices and systems etc. the more accurate our modelling and forecasting can be.
There are a few ways to track different IDs from different systems, but today we are going to focus on the client ID that Google Analytics sets.
The client ID is an anonymous device or browser instance. It is randomly generated and automatically sent with all hits by Analytics libraries.
Google is kind enough to allow you to use the client ID in a cool report called the ‘User Explorer’, which allows you to see 10,000 entries sorted how you wish. The User Explorer report lets you isolate and examine individual, rather than aggregate user behaviour and you can drill down into multiple sessions and interactions within them for these anonymised users.
The only downside to this is that we cannot use any of this data outside of this report. There is no using it in other reports, exporting it or querying it in the API.
Client ID as a Custom Dimension Using Google Tag Manager
Thanks to people like Simo Ahava, recording the client ID as a custom dimension in Google Analytics so that we can use it in multiple reports and export it is not a problem at all. To summarise the steps involved in this process:
2. Create a Universal Analytics Event that sets this value as a custom dimension
3. Set a firing rule for this event to fire after the client ID is set/checked on the window loaded
Now you can set your client ID as a custom dimension and do so much more with the data. But, if you set this event to fire on every page load you can find larger websites end up sending thousands of additional hits to Google Analytics when all you really needed was one.
Using a Cookie to Set Client ID
It makes sense that if you just want to set the Client ID once, why not use the Google Analytics cookie to do this. Unfortunately, they do not easily allow you to piggyback on their methods when they set the cookie and the client ID; so I decided to copy their method and set it in the same way.
The process is simple:
1. Deploy a cookie using GTM when people visit the website
2. In GTM, check whether this cookie already exists or whether it hasn’t been set before
3. If it hasn’t been set before then fire our client ID event and set the custom dimension (if the cookie is already alive, i.e. they’ve already started a session and are on their 2nd, 3rd etc. page then do nothing).
By checking whether this cookie is set or not we can fire the client ID event on the first page a user views on the website. Crucially, this means we do not send the event on every page and inflate the hits we are sending to our clients GA reports!