Expose Client & User ID in Google Analytics
Google Analytics uses a unique identifier to determine if two hits belong to the same user, the unique identifier associated with that particular user must be sent with each hit. GA accomplishes this via Client ID which is a unique, randomly generated string that gets stored in the browser’s cookies, so subsequent visits to the same site can be associated with the same user.
Here is an example of a client id: 15625772458.54738899. As you can see, It’s a combination of unique random number and the first time stamp.
Using cookies allow analytics to identify unique users across browsing sessions, but it cannot identify unique users across different browsers or devices. If your site has its own authentication system, you can use the User ID feature, in addition to the client ID, to more accurately identify a user across all the devices they use to access your site.
By default, Google Analytics offers a report that lets you isolate and examine individual rather than aggregate user behavior via Client ID or User ID (if you have it enabled). The report can be found under the “User Explorer” tab:-
However, these IDs can be only used in the user explorer report and cannot be used as custom dimensions in any of your other reports. And in order to use the client id or user id as dimensions to improve and break down your data, you need to create a custom dimension to retrieve this data and send it back to GA. We will be covering this today, we will learn how to set up custom dimensions via Google tag manager. So let’s start first by the “Client ID” custom dimension:
Client ID Custom Dimension
The first step is to create a session-scoped custom dimension through Google analytics interface. Navigate to GA admin tab, select “Custom Dimensions” and then name your dimension and save it. Please keep in mind the custom dimension index as you are going to need it later:
Now you need to add a custom javascript in GTM to grab the client ID and returns it to the associated property. Below is the javascript code, please note that you need to replace the red text with your own property code:-
function() {
try {
var trackers = ga.getAll();
var i, len;
for (i = 0, len = trackers.length; i < len; i += 1) {
if (trackers[i].get('trackingId') === 'UA-xxxxxx-1') {
return trackers[i].get('clientId');
}
}
} catch(e) {}
return 'false';
}
Create a window loaded trigger to ensure that our client id tag fires only when the custom javascript returns a valid value
Finally, add a Google Analytics event tag and make sure that “Non-interaction” value” is set to “True“. This prevents the events from being calculated into your sessions. Then, Add your custom dimension index and then add the client id variable.
If everything is set up correctly, you should be able to see the client id dimension in your reports as seen below:
User ID Custom Dimension
If you have the user id feature implemented and you want to expose the id in your GA interface. You will need also to create a custom dimension like we did with the client id dimension above. The only difference is the user id custom dimension would be a hit-scoped dimension, unlike the client id which is session-scoped. Why? Because you want only to track logged in users and as soon as they log out you stop collecting.
The rest of the steps would be the same as we explained in the client id part. If you encounter any issues implementing the dimension, please let me know by leaving a comment below.
Entrepreneur focused on building MarTech products that bridge the gap between marketing and technology. Check out my latest product GA4 Auditor and discover all my products here.
wow…. your site fulfil my all requirements..thanks for this amazing information….
You completed a few good points there. I did a search on the topic and found nearly all folks will go along with with your blog.
I need help.
I am trying to make client ID be part of my reports.
I have tried following your steps and got stock on : Create a window loaded trigger
as my custom dimension created in GA is not showing in GTM.
Also, when creating my tag, my page does not have custom dimensions.
Thanks I got it to work. Settings have changed a bit.
Hi Dara,
Glad to know you’ve figured it on you own.
Best,
Ahmed
Dear Ahmed,
Thank you for sharing your method! Unfortunately, I can’t seem to make this work. My custom dimension in GA is being filled with ‘false’. Do you have any idea why and how to fix it? Should I add like a trackingReady trigger (though I don’t know how)?
Hello!
I am wondering also why the client id is not showing up as a trigger type in GTM. Any ideas on this?
Thank you,
Hannah
Hi Ahmed
Maybe you can help me with this on – see link below (I work with David M) and we have some userID/clientID tracking questions you might want to puzzle with and advise us on.
https://www.en.advertisercommunity.com/t5/Google-Analytics-Code/Partial-offline-biz-When-was-cid-created-sending-cid-amp-uid-to/m-p/1244484
I am new with GTM and I have tried many times to setup the client ID. I can make it “fire” in the preview portion of GTM, as It shows up as a fired tag. It will not show up in GA though. Any hints would be appreciated.
Hello,
Regarding custom dimension and sending the Client ID.
I know this article is 2 years old and correct me if Im wrong but isn’t it as simple as just adding the custom dimension settings in the pageview tag in gtm? Do you really have to send an event too to be able to see the dimension in the reports?
Got Some issues, Will You Help us?
Why would you scope User ID to “hit” and not “user”? If it’s a User ID, it should be persistent regardless of if they’re logged in or logged out, and wouldn’t you want to know what they’re doing even while not logged in?
I’d suggest scoping User ID to the “user” and creating another “Logged In” dimension scoped to “hit”.
We are seeing for a client ID Session are creating multiple when compared to User & views (10-12 time more ), when we test manually we could not see the issues, any thoughts.