Google Analytics – How to capture Client ID for reporting purposes

Google Analytics is mainly used for capturing web data, aggregating them and displaying them in charts and graphs. Having said that, there are times where we want to drill down to individuals. In these cases, aggregated data would not help, and there would be a need for unique identifiers to differentiate between users. In Google Analytics, there is such an unique identifier called Client ID. It is a randomly generated string, given to each “new user” to the site. By “new user”, we mean an user that is currently not recorded in Google Analytics. Once obtained by an user, the Client ID will then be stored in the browser cookies, so that subsequent visits can be associated to him/her.

***Note that the Client ID cannot recognize unique users across different devices and browsers***

By default, Client ID is not available for reporting purposes. Yes, you can probably see the Client ID using a debugger, but it is used by Google Analytics to maintain records, not for reporting.
Client ID is displayed in the debugger by default, but it cannot be used for reporting purposes
In order to make use of Client ID for reporting in Google Analytics, we will have to capture it in a separate variable, which is also called a Custom Dimension in Google Analytics.

How to capture Client ID

First of all, we need to create a new Custom Dimension. In order to do so, we need to login to our Google Analytics, and go to the Admin section as shown below. Once we’re there, under PROPERTY, expand Custom Definitions and we will find Custom Dimensions. Click on + NEW CUSTOM DIMENSION. Give our new custom dimension a name (e.g. Client ID) and make sure that the scope is set to User. This will ensure that the value stored in this custom dimension will be persistent and be applied to all hits in the current and future sessions. Therefore, we only need to capture Client ID once in an user’s lifetime. Once we’re done, we should see something like this. Take note of the Index, as this is required information to create the tag later on. Next, we will need to create a new tag to capture the Client ID and place it into the custom dimension we have created. Go to Google Tag Manager, under Variables > User-Defined Variables, create a new variable by clicking NEW. First, we want to create a variable to store the GA Tracking Code. Give it a name (e.g. GA- Tracking Code) and select Utilities > Constant as the variable type. Input the GA Tracking Code in the Value field and save. We can find the Tracking ID in Google Analytics > Admin > Property > Property Settings > Basic Settings. Next, create another variable to store the Client ID. Give it a name (e.g. Client ID) and select Custom JavaScript as the variable type. We will need the code below to capture the Client ID generated by Google Analytics. function() {    try {       var trackers = ga.getAll();       var i, len;       for (i = 0, len = trackers.length; i < len; i += 1) {          if (trackers[i].get(‘trackingId’) === {{GA – Tracking Code}}) {             return trackers[i].get(‘clientId’).toLowerCase().trim();          }       }    } catch(e) {}    return ‘false’; } Once you’re done, save it. Before we create the Google Analytics tag, let’s create the trigger first. A trigger contains the conditions to fire a certain tag. In our case, for simplicity sake, we would like to capture the Client ID every time an user lands on any of our site pages. Give the trigger a name (e.g. Pageview – Client ID). For trigger type, select Window Loaded. This means that the tag will only fire after the browser has finished rendering and displaying everything on the page. The reason for selecting Window Loaded is to ensure that the Client ID has been generated before we try to access it. [Optional] Additionally, we can define one more condition to ensure that the tag fires only when the Client ID is available. Now that we have both the variable and trigger ready, we can create the tag. First, choose a tag type. Select Universal Analytics. Configure as per what is shown in the screenshot below. For Event CategoryAction and Label, the values provided are just for reference. Feel free to use values of your choice. We set Non-Interaction Hit to True, so that this tag will not be considered as an user interaction on the website. If we fail to set this to True, the event will be considered as an user interaction, which will artificially reduce bounce rate. Lastly, check the box that says Enable overriding settings in this tag.  This allows us to define the custom dimension later on. For the Tracking ID, click on the icon on the right of the field and select the variable we have created for GA Tracking Code.   Expand More Settings > Custom Dimensions. Select + ADD CUSTOM DIMENSION. The Index number can be found in Google Analytics after we have created the Custom Dimension there. For the Dimension Value, click on the icon on the right of the field, and you can find the variable (e.g. Client ID) that was created in GTM earlier on. Next, add a trigger to the tag. Select the trigger that we have created earlier on and save the tag. Submit the changes and we are done! Lastly, verify that the new tag is working. We can see that dimension1 is capturing exactly the same value as clientId.  
About admin 31 Articles
Analytics Consultant who loves numbers and data! In love with Adobe Analytics.


  1. Hi Zenny,

    Great article – very insightful indeed. I wonder, once the client ID has been added as a custom dimension, what does the reporting function look like for it?

    Can it be filtered by individual client ID and if so does it include any extra fields in addition to sessions, avg. session duration, bounce rate, revenue, transactions and goal conversion rate?


    • Hi Harry! Apologies for not seeing your comment here and thanks for reaching out to me on LinkedIn! Hope I have answered all your questions there.

      Usually we couple Client ID with events, which are used to captured user interaction on web page (e.g. button click, video play, form fill, etc).

      With Client ID as a dimension and events as metrics, you will be able to see which are the users who have performed a certain action on your website.

      And to answer your 2nd question, yes we can definitely filter by individual Client ID with the intent to find out how is a particular user is doing.

      I will be writing a piece on how to truly identify our own customers and find out what each individual customer is doing on our website to provide a personalized user experience.

  2. Hi Zenny,

    Great article and definitely useful as I’ve used this method to push Client ID for almost all of our clients. However, there are a few that are not using GTM. What is the best way to go about those? What code needs to go directly on the site besides creating custom dimension of course?


    • Hi Emir,

      Glad to hear that you have had some successes with capturing Client ID! For those few that are not using GTM, what platforms are they using? Are they using DTM, or no tag manager at all?

      For Adobe Analytics, DTM made it really easy for us to capture Client ID (Visitor ID). Create a data element with the custom script:
      return _satellite.getVisitorId().getMarketingCloudVisitorID();

      And there you go! As usual, map the data element to the respective eVar (for storing the Visitor ID) in one of your page load rule. And remember to set the expiration of eVar to “Never”.

      But if you are talking about Classic Google Analytics (the legacy one), you’re probably more familiar with _gaq.

      Below is the piece of code will need to directly on the site (replace XXXXXXX with your Tracking Id. In the article, we stored it in a variable name “GA Tracking Code”):

      for (i = 0, len = trackers.length; i < len; i += 1) { if (trackers[i].get('trackingId') === "XXXXXXX") { var clientID = trackers[i].get('clientId').toLowerCase().trim(); } } _gaq.push(['_setCustomVar', 1, 'Client ID', clientID, 1]);

      So what this piece of code does is... use the similar piece of code as seen in the article, instead of returning value, we now store the Client ID in a variable named clientID. Next, using the _gaq.push command, we store the Client ID in a custom variable named "Client ID".

      That should cover it (:

Leave a Reply

Your email address will not be published.