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

Google Analytics identifies a user as unique through a combination of a unique random number and the first timestamp (i.e. the time of the 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 the following four 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 other GA report. That makes analyzing website usage data at the user level quite difficult.

Get the FREE ebook (62 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 a custom dimension in GTM.

Step-3: Navigate to your GTM account and create a new JavaScript variable with the 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 that fires on the window load event. We are going to use this tag to send client ID as a 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 the GA pageview tag on window load event and this is something, I don’t want to do.

Because if I fire the GA pageview tag on the window load event then it will delay the firing of the tag and can create tracking issues in the case some event fires before the pageview. So in order to avoid this problem, I am sending client ID as a 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 a 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 a primary dimension in GA custom reports:

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

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


Do you know the difference between Web Analytics and Google Analytics?

99.99% of course creators themselves don’t know the difference between Web analytics, Google Analytics (GA) and Google Tag Manager (GTM).

So they are teaching GA and GTM in the name of teaching Web analytics.

They just copy each other. Monkey see, monkey do.

But Web analytics is not about GA, GTM.

It is about analyzing and interpreting data, setting up goals, strategies and KPIs.

It’s about creating strategic roadmap for your business.

Web Analytics is the core skill. Google Analytics is just a tool used to implement ‘Web Analytics’.

You can also implement ‘Web analytics’ via other tools like ‘adobe analytics’, ‘kissmetrics’ etc.

Using Google Analytics without the good understanding of ‘Web analytics’ is like driving around in a car, in a big city without understanding the traffic rules and road signs.

You are either likely to end up somewhere other than your destination or you get involved in an accident.

You learn data analysis and interpretation from Web analytics and not from Google Analytics.

The direction in which your analysis will move, will determine the direction in which your marketing campaigns and eventually your company will move to get the highest possible return on investment.

You get that direction from ‘Web analytics’ and not from ‘Google Analytics’.

You learn to set up KPIs, strategies and measurement framework for your business from ‘Web analytics’ and not from ‘Google Analytics’.

So if you are taking a course only on 'Google Analytics’, you are learning to use one of the tools of ‘Web analytics’. You are not learning the ‘Web analytics’ itself.

Since any person can learn to use Google Analytics in couple of weeks, you do no get any competitive advantage in the marketplace just by knowing GA.

You need to know lot more than GA in order to work in Web analytics and marketing field.

So what I have done, if you are interested, is I have put together a completely free training that will teach you exactly how I have been able to leverage web/digital analytics to generate floods of news sales and customers and how you can literally copy what I have done to get similar results.

Here what You'll Learn On This FREE Web Class!

1) Why digital analytics is the key to online business success

2) The number 1 reason why most marketers are not able to scale their advertising and maximize sales.

3) Why Google and Facebook ads don’t work for most businesses & how to make them work.

4) Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

5) The number 1 reason why conversion optimization is not working for your business.

6) How to advertise on any marketing platform for FREE with an unlimited budget.

7) How to learn and master digital analytics and conversion optimization in record time.


My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

Himanshu Sharma

Digital Marketing Consultant and Founder of

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers' purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years of experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence. The Digital Analytics Association is a world-renowned not-for-profit association that helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!