27 June 2022
Client ID in GA4 - What is it and how to get it in your report?
What is Client ID?
If you’re new to Google Analytics, you may wonder how it differentiates between two distinct visitors? The short answer is ‘Client ID’.
Client ID is a unique identifier given to a browser-device pair when a user first arrives at your website. It is used to identify distinct website visitors and associate all on-site activity and interactions with your website back to the same user. Not just in a single website session, but also over multiple sessions.
The Google Analytics (GA) Client ID is stored in a cookie named “__ga” (unless customised otherwise).
Both Universal Analytics and Google Analytics 4 (GA4) use client ID in the same way. However in the context of GA4 you may also see Client ID referred to using the synonym of “Device ID” from within the GA4 property settings -> reporting identity configuration.
What does Client ID do?
As a visitor returns to your website multiple times via the same Device/Browser combination, Client ID is used to identify the same returning user and ensure a distinct user count. Hence, metrics such as Total Users and New Users are derived from the use of Client ID, and help give you insight into new vs returning user behaviour, as well as your website’s user retention rate.
Client ID is also used to associate engagement with different ad campaigns back to the same user, which facilitates the construction of multi-channel funnel attribution reports in GA. For example: Every-time a user arrives at your site via a campaign tagged URL, Google associates that campaign with the visitor’s Client ID. This is the basis for your GA4 Attribution report, which shows how your marketing efforts contribute to a conversion on your site.
Every Client ID has the structure: ‘GA.1.1’ + unique identifier + Unix timestamp. The Unix timestamp is the exact time and date the user first interacted with your page. Therefore, capturing the last 10 digits in the Client ID tells you the timestamp of first user interaction and give you access to interesting metrics, such as time from the first interaction to completion of a conversion event.
Why include Client ID in GA4 reporting UI?
Although Client ID is the default basis for your user metrics and reports in GA, this parameter doesn’t appear in its raw form within the GA4 user interface and cannot be accessed via the exploration (custom) reports or via Data Studio. Instead what you see is aggregated metrics such as “users” which are based on the Client ID, but not Client ID as a value itself.
Having access to Client ID enables you to group behaviour by client, dig deeper into specific user sessions and analyse their behaviours further, especially when you observe unexpected actions. Without visibility of Client ID, it would be challenging to perform deeper user behaviour analysis.
In addition, some integrations with GA have historically used client ID to join offline and online activity. An example may be a CRM integration that captures the GA client ID with new leads. If a strong prospective lead comes in, you may wish to review what pages that lead viewed on your website in GA4 via the matched Client ID parameter.
Please note that if you’ve enabled BigQuery exports in your GA4 property (and we recommend you do), you can access the client ID value via the column user_pseudo_id (refer to BigQuery Export schema). However, by placing the client_id in a GA4 user parameter, you can now access this value in your front-end reporting, which helps with comparing BigQuery and front-end reporting UI results, and in our experience, it can be extremely useful when debugging unexpected front-end reporting behaviour.
How to capture Client ID in GA4?
Here we will show you how to extract the Client ID from the _ga cookie via GTM and then pass the client ID as a custom parameter to GA4, which will let you see it within the reporting UI and in other tools that depend on GA4 data such as Data Studio.
Before we start, if you’re curious about where we will pull the Client ID value from, go to your website and open the Chrome Developer tool - by right clicking and choosing ‘Inspector’.
In the ‘Application’ tab, under the ‘Cookies’ section, you should be able to find your Client ID next to the parameter ‘_ga’.
Great! Now that you know where Client ID is stored, we can extract this information using a custom variable in GTM.
Step 1 Visit your container in https://tagmanager.google.com/ and go to Variables
Step 2 Create a First-Party cookie variable to capture Client ID from the cookie. Cookie name is ‘_ga’
Step 3 The _ga cookie and Client ID value in our case has a prefix of ‘GA1.1’, which we don’t actually need to keep. We will use a custom Javascript variable in GTM to slice the first 6 characters in the _ga cookie and discard them.
However, after stripping the prefix, we also want to make sure the Client ID will be recognised as a string and not a number (Read below for more details). Therefore, we’ve added a prefix “c” at the front.
Step 4 Now you’re ready to use this custom Javascript variable to send the Client ID to GA4 as a custom event parameter. Choose your main GA4 configuration tag that fires on all pages and add in this parameter. Since Client ID is unique for each user, remember to add this parameter in the ‘User property’ section and not ‘Event parameter’ section.
You can choose to add this user parameter directly on the Configuration tag, or in an Event settings variable. We prefer using the Event settings variable.
Step 5 Don’t forget to enable Client ID as a custom parameter with user-scope in GA4 at: Configure (Left navigation bar) > Custom definitions > Create. Make sure the User property exactly matches the ‘Property name’ you set in GTM (client_id in the this example).
Step 6 Now, let’s verify Client ID is being captured and sent to GA4 correctly in GTM preview mode. Place your GTM container in Preview mode and review the debug panel, inspect your GA4 config tag and check for User Properties being set with “client_id”.
Client ID is received in Google Analytics 4 as indicated in the orange box
Verifying Client ID is being correctly captured
Louder has found cases where GA4 has truncated the value of Client ID. This happens as it is treating the ‘.’ as a decimal point, resulting in the Client ID string to be seen as a number. In GA4 reports, you only get up to 7 digits after a decimal place. The accurate Client ID has 10 numbers after the ‘.’ - which means you’re not getting the same number.
This matters because the shortened number cannot be used for matching with other data sets, especially if you try to export it to other forms.
We suggest adding at least a character before the number (e.g. c) so GA4 recognises this as a string.
Voilà - that is everything! You should be getting Client ID in your GA4 standard and custom UI as a custom user property now.