In this article, I am going to talk about sending the Google Analytics Client ID via GTM (Google Tag Manager).
Understanding Client ID in Google Analytics
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 the Google Analytics _ga cookie.
The _ga cookie is made up of the following four fields:
The first field is the version number like GA1.
The second field is the number of components at the domain separated by a dot.
By default, the _ga cookie is set on the top-level domain with the root level (/) path. So if you have set a cookie at the top-level domain like optimizesmart.com then the second field would have a value of 2 as there are 2 components separated by a dot. One component is ‘optimizesmart’ and the second component is ‘com’.
If you have set up a cookie at the sub-domain level, like analytics.optimizesmart.com, then the second field would have a value of 3 as there are now three components separated by a dot. The first component is ‘analytics’. The second component is ‘optimizesmart’. The third component is ‘com’
The third field is a random unique ID (randomly generated number). Here 1368576646is the random unique id.
The fourth field is the first timestamp i.e. the time when the cookie was first set for the user. Here 1596648643is the first timestamp.
The third and fourth fields together make the client ID. So, the client ID would be 1368576646.1596648643
To view your Google Analytics cookie (Client ID) for a specific site in the Chrome browser, open the site and follow the below steps
Step-1: Click on three dots at the left corner of your Chrome browser and then click on ‘Settings’.
Step-2: Scroll down and click on ‘Cookies and other site data’ under ‘Privacy and security’.
Step-3: Scroll down and click on ‘See all cookies and site data’.
Step-4: Look for your website domain and click on it.
Step-5: Click on ‘_ga’ and in the content, you will find your client ID.
A 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, Google Analytics cannot identify unique users across different web browsers and devices, by default.
In GA reports, Client ID is available as a primary dimension only in theUser Explorer report:
The User Explorer report, shows website usage data (sessions, average session duration, bounce rate, revenue, etc) for each user, via the Client ID dimension:
Since Client ID dimension is available only in the User Explorer report, you cannot use this dimension in any other GA report. That makes analyzing website usage data at the user level quite difficult.
The only solution to this problem is to collect client id data through your efforts and send it to GA as a custom dimension.
Since Client ID is completely anonymous, it cannot be used to personally identify a person (unless you choose to combine it with personally identifiable data).
Sending Client ID to GA as a custom dimension via GTM
Follow the steps below to send Client ID to GA as a custom dimension via GTM/
Step-1: Navigate to your GA property and click on ‘Admin’.
Step-2: Click on ‘Custom Definitions’ under ‘Property’.
Step-8: Note down the index number of your custom dimension:
We will use this index number later while setting up a custom dimension in GTM.
Follow the below steps to configure GTM.
Step-9: Navigate to your GTM account.
Step-10: Click on the ‘Variables’ link in the left-hand side navigation menu.
Step-11: Click on ‘New’ under ‘Use-Defined Variables’.
Step-12: A new window will pop up like below. Give it a proper name and click on ‘Variable configuration’.
Step-13: In ‘Variable configuration’ you will see several types of user-defined variables as below. Click on ‘Custom JavaScript’.
This variable is a custom JavaScript function which is used to pass website parameters within variables.
Step-14: Paste the following code into the code window.
function(){
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 statementis used to test a block of code for errors. The ‘catch’ JavaScript statement is used to handle the error.
Now let’s 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:
Step-15: Click on ‘Tags’ and then click on ‘New’.
Step-16: Give your tag a descriptive name and click on ‘Tag configuration’.
Step-17: An overlay will appear on the right-hand side with a list of tag templates. Select ‘Google Analytics: Universal Analytics’.
Step-18: Click on the drop-down under ‘Track type’ and select ‘Event’.
Step-19: Now In the event category type ‘Client ID’.
Step-20: Now click on the ‘+’ icon under ‘Event action’ and select the JavaScript variable that we created earlier (Return Client ID).
Step-21: Now similar to the earlier step, click on the ‘+’ icon under ‘Event value’ and select the ‘Page path’ variable.
Step-22: Set ‘Non-Interaction Hit’ to ‘True’ and your tag will look like below:
Step-23: Now select the Google Analytics setting variable. Here {{GA Default Settings}} is a Google Analytics settings variable that I use. It returns the property ID.
Then mark the checkbox ‘Enable overriding settings in this tag’ and click on ‘More settings’ and then on ‘Custom Dimensions’.
Step-24: Now click on ‘+Add custom Dimension’.
Step-25: Now in the input box under ‘Index’, type the index number we noted earlier. And then click on the ‘+’ icon under ‘Dimension value’ and select the JavaScript variable that we created earlier (Return Client ID).
Now let’s create a trigger for this event.
Step-26: Click on ‘Triggering’.
Step-27: Click on the ‘+’ icon.
Step-28: Give your trigger a proper name and click on ‘Trigger configuration’.
Step-29: An overlay will appear on the right-hand side. Select ‘Window Loaded’.
Step-30: Select the radio button ‘Some Window Loaded Event’.
Step-31: Click on the drop-down ‘Click Classes’ and select ‘Return Client ID’ variable.
Step-32: Select operator ‘does not equal to’ and value ‘false’.
Now you may ask, why am I not using the ‘Container Loaded’ event to send the custom dimension?
This is because the ‘Return Client ID’ JavaScript variable does not seem to resolve on the ‘Container loaded event’.
And then check for Window Load in Summary tab It seems to resolve on window load event:
To send Client ID as a custom dimension via the pageview tag, I would have to fire the GA pageview tag on the window load event and this is something, I don’t want to do.
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 that some event fires before the pageview. So, to avoid this problem, I am sending client ID as a custom dimension via event tag.
Step-2: Now In the input box under URL, type your website URL and click on ‘Start’.
Step-3: A new tab will open with your website URL. Switch back to the debugger tab and click on the window loaded in the ‘Summary’ tab.
As you can see from the above image, our event tag is firing on window load.
Click on the event to check more details.
Google Analytics reports with Client ID
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 the ‘Top Events’ report under Behavior > Events:
Frequently Asked Questions About Sending Google Analytics Client ID via GTM (Google Tag Manager)
What is Client ID?
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.
Where is Client ID stored?
Client ID is stored in a Google Analytics cookie. Google Analytics cookie can exist only on the device and browser where it has been set up. For this reason, by default, Google Analytics can not identify unique users across different web browsers and devices.
Is Client ID used in Google Analytics reports?
The Client ID dimension is available only in the user explorer report.
The user explorer report shows website usage data (sessions, average session duration, bounce rate, revenue, etc) for each user, via the Client IDdimension.
You can not use this dimension in any other GA report. That makes analyzing website usage data at the user level quite difficult.
Can I send Client ID to Google Analytics as a custom dimension?
Yes. To get around the issue of Client ID only being available as a dimension in the user explorer report, you can collect Client ID data through your own efforts and send it to GA as a custom dimension.
Follow the step by step guide in this article to send client ID to GA as a custom dimension via GTM.
Register for the FREE TRAINING...
"How to use Digital Analytics to generate floods of new Sales and Customers without spending years figuring everything out on your own."
Here’s what we’re going to cover in this training…
#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 BeyondSECOND EDITION OUT NOW!
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.
About the Author
Himanshu Sharma
Founder, OptimizeSmart.com
Over 15 years of experience in digital analytics and marketing
Author of four best-selling books on digital analytics and conversion optimization
Nominated for Digital Analytics Association Awards for Excellence
Runs one of the most popular blogs in the world on digital analytics
Consultant to countless small and big businesses over the decade
Learn and Master Google Analytics 4 (GA4) - 126 pages ebook
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.