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:-

user-explorer-ga

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:

client-id-custom-dimension

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

client-id-trigger

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.

cid-gtm-trigger

If everything is set up correctly, you should be able to see the client id  dimension in your reports as seen below:

client id report

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.

user-id-custom-dimension

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.

mm
Ahmed launched his first digital campaign in 2013 through participating in Google Online Marketing Challenge. He competed with over 12,000 students from 80 countries to win the first place in Africa & MENA region and one of the best five campaigns in the world. Today, he works as an Associate Digital Director at Keyade Middle East.

5 Comments

  1. Dara

    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.

Leave a Reply

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