27 June 2022

Client ID in GA4 - What is it and how to get it in your report?

Client ID in GA4

What is Client ID?

If you’re new to Google Analytics, you may wonder how it differentiates between 2 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.

Reporting identity

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.

Conversion path

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.

Client ID structure

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’.

1 - Louder website

In the ‘Application’ tab, under the ‘Cookies’ section, you should be able to find your Client ID next to the parameter ‘_ga’.

2 - Client ID

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

3 - Tag Manager

Step 2 Create a First-Party cookie variable to capture Client ID from the cookie. Cookie name is ‘_ga’

4 - 1st-party cookie variable

Step 3 (Optional) The _ga cookie and Client ID value in our case has a prefix of ‘GA1.1’, which we don’t actually need to keep. Therefore we will use a custom javascript variable in GTM to slice the first 6 characters in the _ga cookie and discard them.

5 - Custom Javascript variable

Step 4 Now you’re ready to use this custom javascript variable to send the Client ID to GA4 as a custom 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

6 - Config tag

Step 5 Don’t forget to set up 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).

5 - Custom dimension

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”.

7 - GTM preview

Client ID is received in Google Analytics 4 as indicated in the orange box

7 - GA debug

Voilà - that is everything! You should be getting Client ID in your GA4 standard and custom UI as a custom user property now.



About Sophia Vu

Sophia Vu is a junior data analyst. In her spare time, she enjoys playing music, cooking and long walks on the beach.