Update time: January 17, 2025
This article introduces how to get the Client ID as a variable in GTM.
There are many methods:
1st Party Cookie
GA4 will store the Client ID in the first-party Cookie _ga, as follows:
In GTM, click「Variables」——「New」——「Choose a variables type to begin setup…」——「1st Party Cookie」,Name it “cookie_ga”, and make the following settings:
Then create another variable, click「Variables」——「New」——「Choose a variables type to begin setup…」——「1st Party Cookie」,Name it “Client ID-cookie”, and make the following settings:
Finally, preview and debug to see if this variable Client ID-cookie can obtain the Client ID:
Read More:Explanation of Cookie Values Used by Google Analytics 4
gaGlobal
After the GA4 tracking code is loaded, it will be represented as the Client ID in window.gaGlobal.vid, which can be viewed in the browser developer tools:
It can be get through custom JavaScript variables. click「Variables」——「New」——「Choose a variables type to begin setup…」——「1st Party Cookie」,Name it “Client ID-gaGlobal“, and make the following settings:
Next, preview and debug to see if this variable Client ID-gaGlobal can obtain the Client ID:
Note: gaGlobal will be slow to obtain the Client ID and is not recommended.
customTask
GA4 does not support customTask yet.
Read More: