How to send Client ID to Google Analytics via Google Tag Manager

Google Analytics identify a user as unique through a combination of unique random number and the first time stamp (i.e. the time of first visit).

This combination is called the ‘Client ID’.

Client ID is created and assigned by Google Analytics cookie _ga.

_ga cookie is made up of following 4 fields:

The third and fourth field together make, what we called the client ID:

Google Analytics cookie can exist only on the device and browser where it has been set up.

Since client ID is stored in a GA cookie, the client ID can exist only on the device and browser where it has been set up.

Because of this reason, by default, Google Analytics can not identify unique users across different web browsers and devices.

In GA reports, ‘client id’ is available as a primary dimension only in the ‘User Explorer’ report:

The user explorer report, show website usage data (sessions, average session duration, bounce rate, revenue etc) for each user, via the ‘Client IDdimension :

Since the ‘Client ID’ dimension is available only in the ‘user explorer’ report, you can not use this dimension in any another GA report.

That makes analyzing website usage data at the user level quite difficult.

Get the E-book (52 Pages)

Get the E-Book (37 Pages)


The only solution to this problem is to collect client id data through your own efforts and send it to GA as a custom dimension.

Since ‘client id’ is completely anonymous, it can not be used to personally identify a person (unless you choose to combine it with personally identifiable data).

Follow the steps below to send client ID to GA as a custom dimension via GTM:

Step-1: Navigate to your GA property and create a new custom dimension with user level scope:

Step-2: Note down the index number of your custom dimension:

We will use this index number later while setting up custom dimension in GTM.

Step-3: Navigate to your GTM account and create a new JavaScript variable with following code:


try {

   var tracker = ga.getAll()[0];

   return tracker.get(‘clientId’);

 } catch(e) {

   return false;



This variable returns client ID if there is no error. Otherwise it returns false.

The ‘try’ JavaScript statement is used to test a block of code for errors.

The ‘catch’ JavaScript statement is used to handle the error.

Step-4: Create a new event tag which fires on window load event. We are going to use this tag to send client ID as custom dimension to GA:

Note: Here {{GA Default Settings}} is a Google Analytics Settings Variable, I use. It returns the property ID.

Now you may ask, why I am not using the pageview tag (used to send GA data) to send the custom dimension.

The ‘Return Client ID’ javascript variable does not seem to resolve on pageview event:

It seems to resolve on window load event:

In order to send client ID as custom dimension via pageview tag, I would have to fire GA pageview tag on window load event and this is something, I don’t want to do.

Because if I fire GA pageview tag on window load event then it will delay the firing of the tag and can create tracking issues, in case some event fire before the pageview.

So in order to avoid this problem, I am sending client ID as custom dimension via event tag.

I do not want this event tag to impact bounce rate that is why I have set the event, as non-interaction event:

I do not want the event tag to fire, in case the client ID is not successfully retrieved.

That is why, I set the following condition, while creating the window trigger:

Step-5: Preview and publish your GTM container.

You can now use the client ID as primary dimension in GA custom reports:

You can now use the client ID as secondary dimension in GA standard reports:

You can also see client ID data in ‘Top Events’ report under (Behavior > Events):

Most Popular E-Books from OptimizeSmart

Learn to read e-commerce reports book banner

How to learn and master Web Analytics and Google Analytics?

Take the Course

Check out my best selling books on Web Analytics and Conversion Optimization on Amazon

How to get lot more useful information?

I share lot more useful information on Web Analytics and Google Analytics on LinkedIn then I can via any other medium. So there is really an incentive for you, to follow me there.

Himanshu Sharma

Certified web analyst and founder of

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues. If you have any questions or comments please contact me.

  • Over twelve years' experience in SEO, PPC and web analytics
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of and

I am also the author of four books:

error: Alert: Content is protected !!