Set Client ID to Custom Dimensions in GA4(2025)

Google Analytics BCS 3 years ago (2023-01-16) 3963 Views 0 Comments

Update time: August 4, 2025

This section introduces how to Set Client ID to Custom Dimensions(aka:User Properties, User Scope Custom Dimension) in GA4.

Step 1 : readAnalyticsStorage API Get Client ID

This is an API provided by GTM to obtain Client ID/Session ID.

It uses a custom variable template. You need to create a custom variable template and use the readAnalyticsStorage API within it to retrieve the Client ID/Session ID. Some code has been shared, such as this: https://github.com/luratic/ga4_get_client_id_and_session_info. After downloading it, import it into「 Variable Templates」 under 「Templates」:

Set Client ID to Custom Dimensions in GA4(2025)

In GTM, click「Variables」——「New」——「Choose a variables type to begin setup…」——「GA4 – Get Client Id & Session Info (Safe API)」,Name it “Client ID“, and make the following settings:Set Client ID to Custom Dimensions in GA4(2025)

Read more:How to Get Client ID to Variable in GTM?

Step 2 : Set up Custom Dimensions

Secondly, create a Google Tag: Event Settings variable in GTM and set it in “Google Analytics User Properties” as follows (If you have already created Google Tag: Event Settings, add client_id settings in Property Name):Set Client ID to Custom Dimensions in GA4(2025)

Name it “Common Event Parameter”.

Next, set the variable Common Event Parameter to the Event Settings Variable in the GA4 basic page tracking code(Note that this setting is in the GA4 base page tracking code.), such as:

Set Client ID to Custom Dimensions in GA4(2025)

 

Step 3 : Preview and Release

Finally, preview testing and release:Set Client ID to Custom Dimensions in GA4(2025)

The test is as expected and can be released and data collected.

Read  More:

 

Step 4 : Custom Definitions

This custom dimension also needs to be registered in Custom definitions before it can be used. Create a custom dimension as follows in Custom definitions:

Set Client ID to Custom Dimensions in GA4(2025)

Step 5 : Verify data in Real-time Report

Generally, after 24 hours, we can see the data in GA4, such as:

Set Client ID to Custom Dimensions in GA4(2025)


If you don't understand, You can leave a comment below.
Like (1)
Post my comment
Cancel comment
Expression Bold Strikethrough Center Italic

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website