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」:
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:
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):
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:
Step 3 : Preview and Release
Finally, preview testing and release:
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:
Step 5 : Verify data in Real-time Report
Generally, after 24 hours, we can see the data in GA4, such as: