January 23, 2024
A Guide to Google Analytics Client ID
Updated: January 23rd, 2024
If you have landed on this blog post and want to learn about this topic, congratulations. This indicates that you want to go beyond the beginner level. It’s time to go under the hood and understand how Google Analytics generates and uses client IDs.
In this blog post, I will explain what Google Analytics client ID is, how it works, its limitations, and many other things.
Table of contents
Here’s what you will learn in this article
- What is Google Analytics client ID?
- How does the client id work?
- How to find the client ID?
- Why would you need to get the GA client ID in the first place?
- The Limitations of Google Analytics Client ID
- Differences between client ID and user ID in Google Analytics
- Final words
What is Google Analytics client ID?
The client ID is a unique identifier that Google Analytics generates for a browser when a user visits your website. It helps track user interactions and activities during a session, allowing you to understand your audience’s behavior better.
The client ID is generated randomly, and its primary purpose is to distinguish between new and returning visitors, as well as to help organize and aggregate user behavior data (in other words, linking multiple events to the same visitor).
However, it is important to note that the client ID is different from the user ID and has its own set of limitations and use cases. But I’ll talk more about that a bit later.
How does the client id work?
The client ID is stored as a first-party cookie (_ga) on the user’s device or browser when they visit a website with a Google Analytics tracking code. This unique identifier remains persistent and unchanged for up to two years by default (in theory), ensuring that subsequent visits and actions by the same user are recognized and attributed to the same client ID.
However, more and more browsers are limiting the cookie’s lifetime, so in reality, its lifespan is usually shorter.
As the user interacts with the website, Google Analytics collects various data points, such as page views, events, and e-commerce transactions. These data points are tied to the client ID, allowing Google Analytics to aggregate user behavior data. This happens by default.
It is important to note more than once that the client ID is device and browser-specific, meaning it cannot track users across different devices or browsers. If a user visits the same website from different devices or browsers, each instance will generate a separate client ID, and their interactions will be recorded as separate sessions (and users) in Google Analytics.
However, if a visitor navigates from one website (domain) to another, it is possible to unify the client ID by using cross-domain tracking.
How to find a Google Analytics client ID?
There are several options to do that.
#1. Checking in Google Analytics 4 interface
To locate the client ID in Google Analytics 4, follow these steps:
Log in to your Google Analytics 4 account. Navigate to the Explore section. Click on User Explorer.
Within the User Explorer, you will see the client ID listed for each individual user.
#2.Bigquery
In Google BigQuery, every event contains a field called user_pseudo_id. It contains the client ID.
#3. Checking a _ga cookie
This option is a bit more technical.
Open the developer tools in your browser (usually accessible via F12 (on Windows) or right-clicking the page and select “Inspect”). Navigate to the Application tab (I am using Google Chrome in this example).
Go to Cookies and select your domain. Then locate the _ga cookie. Its value might look something like this (of course, in your case, the value will be different):
The last two numbers (with a dot between them) are the client id. So if you look at the screenshot above, the client ID value is 40030803.167153367.
If you want/need it, you can access that cookie with Google Tag Manager. In GTM, go to Variables > New > 1st party cookie and enter the following settings (name it exactly as I show in the screenshot below):
This variable will return the full value of the cookie, e.g., GA1.1.40032303.1671533621. If you want to parse just the last two numbers, go to Variables > New > Custom JavaScript and paste the following code (it will work only if you have named the 1st party cookie variable exactly as I did in the screenshot above).
function() { return {{ga cookie}}.substring(6) }
This code will remove the first six characters of the _ga cookie, and the result will be 40032303.1671533621 (or any other numbers that were stored).
#4. Using the “get” command in gtag()
Google Analytics 4 tracking code (a.k.a. GTAG) offers a set of commands that you can use for your convenience. One is get that can return values of certain fields/parameters in GA4.
Here’s an example of a command that you can execute right in your Google Chrome console:
gtag('get', 'G-XXXXXX', 'client_id', function(clientId) {console.log(clientId)})
Replace G-XXXXXX with your GA4 property’s measurement ID. Of course, if your developers want to use it, they will need to modify the code (the console.log part) in order to pass the client_id’s value to other parts of your website’s code.
#5. Using a GTAG GET API tag template in Google Tag Manager
This option uses the same get command from the previous tip. But Simo Ahava made this a bit more convenient for Google Tag Manager users. He created a tag template that you can add to your GTM container and then push the values of certain GA fields (including client_id) to the data layer.
In Google Tag Manager, go to Templates > Tag Templates > Search Gallery and locate GTAG GET API template. Add it to workspace.
Then go to Tags > New > Tag Configuration > GTAG GET API. Paste your GA4 measurement ID, name the tag, and save it. Do NOT add a trigger to it.
G-
Then open your existing Google tag (a.k.a. GA4 Config Tag) (if you don’t have it, read this article on how to install GA4 with Google Tag Manager.
In the Advanced Settings of that tag click Tag Sequencing > Fire a tag after GA4 config tag fires and choose the GTAG GET API tag you just created.
Hit the Preview button in GTM. On the Preview mode’s left sidebar, you will start seeing a new dataLayer event that contains the client_id. If you want to use it, create a Data Layer variable for it (client_id).
Important: don’t send the client ID as a Custom Dimension to GA4. Otherwise, it can cause cardinality issues.
Why would you need to get the GA client ID in the first place?
I have some examples. But the answer depends on your situation and what you want to achieve. For most GA4 users, fetching the client ID is not needed.
Client ID is required if your company wants to send data to GA4 with measurement protocol. So if your developers want to do this, first, they need to fetch the Client ID and store it somewhere in your database or CRM. After that, they can send events from your server directly to GA4 servers.
Or maybe you are firing some tags in Google Tag Manager (e.g., that submit data to your internal system/CRM), and together with it, you want to pass the GA client id.
However, I want to remind once again, the you should not send Client ID as an event-scoped or user-scoped custom dimension to GA4. Otherwise, you will be facing high-cardinality issues.
The Limitations of Google Analytics Client ID
Even though Client ID is a vital part of Google Analytics, it has some limitations you need to be aware of.
Cross-device and cross-browser tracking
The client ID is specific to a particular device and browser. As a result, it cannot track users across different devices or browsers.
If a user visits the same website from different devices or browsers, each instance will generate a separate client ID, and their interactions will be recorded as separate sessions in Google Analytics. This can lead to fragmented data and a less accurate understanding of user behavior.
Cookie deletion and blocking
Users can delete or block cookies, resulting in the loss of the stored client ID. In such cases, when the user returns to the website, a new client ID will be generated, and they will be treated as a new visitor by Google Analytics. This can cause discrepancies in tracking returning visitors and affect the accuracy of the data.
Differences between client ID and user ID in Google Analytics
Sometimes, Google Analytics users (especially beginners) might confuse user ID with client ID. Even though Google Analytics supports both of them, they serve different purposes.
I talk more about this topic here, but if you are interested in a general overview, here it is.
Tracking scope
Client ID is used to track individual sessions and interactions on a specific device and browser. It is unable to track users across multiple devices or browsers.
User ID enables cross-device and cross-browser tracking, allowing you to track and analyze user behavior across multiple devices and browsers. This provides a more holistic view of the user’s journey and interactions with your website.
Storage
The client ID is generated automatically by Google Analytics and stored as a first-party cookie (_ga) in the user’s browser.
User ID (of a registered user) is stored in your system’s/website’s database and then sent to Google Analytics.
Data Accuracy
The accuracy of the client ID can be affected by cookie deletion or blocking, which may result in fragmented data and a less accurate understanding of user behavior.
As the user ID is tied to an authentication system, it is generally more accurate and reliable for tracking user behavior, even if cookies are deleted or blocked.
Use cases
The client ID is useful for tracking general user behavior, such as new vs. returning visitors, average session duration, and conversion rates. Even though people can block or delete cookies, client id is still useful to tie events of the same visitor to the same session.
The user ID enables more advanced tracking, such as cross-device analysis. However, if your website does not have a login feature, user ID in GA4 is not for you.
Google Analytics Client ID: Final words
And that’s the end of this blog post.
We delved into the world of Google Analytics client ID, examining its role in tracking user behavior on websites. This article explained the concept of client ID and how it operates. Even though Client ID seems like a small thing, it’s a pretty important part when it comes to aggregating events into sessions and connecting them with a single user.
If you want to find/check the client ID, you can either use the browser’s developer tools (and check the _ga cookie), or you can utilize the GTAG get method.
However, it’s not perfect, so when you think about it, always have a pound of salt with you.
Last, do not confuse the client ID with the user ID. They are different things designed to serve different purposes.
12 COMMENTS
Hi Julius,
could you explaine how to config a Ga4 tag configuration with client id? Should I use Fields to set and set client_id and also use User property and set there client_id one more time? Could it be the same name if i set client id in both options: fields to set and user property in configuration tag?
I watched your video about user_id, and you mentioned the name of user id variable have to be diffrent.
GA4 tracks client id automatically. You don't need to set it.
Julius,
but if I want to use client id as a custom dimension in different reports in ga4, I should create the custom dimension, but you mentioned it's not correct.
Custom dimensions in Ga4 should not have more than 500 unique values per day. Otherwise, you will face high-cardinality issues and see a lot of (other) in your reports.
In ga4, clientId dimension is not available , when i try to set client id as a custom dimension , in some case the dimension not set,
my requirements is to fetch data using code based on clientId
If you are using GTM to implement GA4 (as opposed to gtag), how does one get client_id to be used in scripts and functions on the page? The gtag get api plugin for GTM from Simo Ahava makes client_id available in the dataLayer, but there does not seem to be a good way to access fields in the dataLayer from outside of GTM. We can see client_id exists nested deep in the dataLayer via console.log, but cannot figure out how to access the value for client_id via code...
In GA4, how cookie-less tracking works?
is there an alternative for client id? if i am sending data from server side, and no original client id of the user... can i replace client id with the user id?
Hmm, why do I get an error gtag is not defined?
gtag('get', 'G-KRYJELJR53', 'client_id', function(clientId) {console.log(clientId)})
Hello Julius! Is it possible to grab client id with form submission? Like in a hidden field. Meaning extract it somehow from cookies
I have a situation where I need to get the client_id and session_id and store them as variables in GTM. Previously I was doing this using a custom html tag to load GA4 using gtag.js. I would like to remove that custom html tag and just use the 'new' Google Tag. When using the Google Tag are these variables still created and accessible? Would I still be able to use Simod template to do this?
Hello, when I visit the "user exploration" tool in GA, I don't get the "client ID" but instead the "Efective user ID". I think they're referring to the same thing, but changed the name?