Sending Google Analytics Client ID via GTM (Google Tag Manager)

Follow the steps below to create and pass the client ID custom parameter (with user scope) along with the event named ‘get_user_data’ to our GA4 property.

Step-1: Login to your Google Tag Manager account and then click on the ‘Templates‘ link:

click on the ‘Templates‘ link

Step-2: Click on the ‘Search Gallery‘ button under the ‘Tag Templates’ section:

Click on the ‘Search Gallery‘ button

Step-3: Click on the magnifying glass to display a search box:

Click on the magnifying glass
import tag template

Step-4: Type ‘GTAG GET API‘ in the search box and then click on the first search result:

Type ‘GTAG GET API‘ in the search

Step-5: Click on the ‘Add to workspace‘ button:

Click on the ‘Add to workspace‘ button

Step-6: Click on the ‘Add‘ button:

Click on the ‘Add‘ button

You should now see the new tag template listed under the ‘Tag Templates‘ section:

see the new tag template listed under the ‘Tag Templates‘ section

Now, we are going to create a new tag based on this tag template.

Step-7: Click on the ‘Tags‘ link and then click on the ‘New‘ button to create a new tag:

click on the ‘New‘ button to create a new tag

Step-8: Name the new tag ‘Gtag get api‘:

Name the new tag ‘Gtag get api‘

Step-9: Click on the ‘choose a tag type’ button:

Click on the ‘choose a tag type button

Step-10: Scroll down and then click on the custom template ‘GTAG GET API‘:

click on the custom template ‘GTAG GET API‘

Step-11: Enter the measurement ID of your GA4 property and then click on the ‘Save‘ button:

Enter the measurement ID of your GA4 property

Step-12: Click on the ‘Save Tag‘ button, as your tag will not have any firing trigger:

Click on the ‘Save Tag‘ button as your tag will not have any firing trigger

Now, we need to edit the GA4 configuration tag (the Google tag we used to install and enable the GA4 tracking) and add the tag ‘Gtag get API‘ in a tag sequence.

Step-13: Find and edit your Google tag and then click on the ‘Advanced Settings‘ link:

Find and edit your Google tag and then click on the ‘Advanced Settings‘ link

Step-14: Click on ‘Tag Sequencing‘:

Click on ‘Tag Sequencing‘ 1
‘Tag Sequencing‘

Step-15: Click on the checkbox ‘Fire a tag after Google Tag – All Pages fires‘:

Click on the checkbox ‘Fire a tag after Google Tag – All Pages fires‘

Step-16: Click on the ‘Select tag‘ drop-down menu:

Click on the ‘Select tag‘ drop down menu

Step-17: Click on the ‘Gtag get api‘ tag:

Click on the ‘Gtag get api‘ tag

Step-18: Click on the ‘Save‘ button to save your tag:

save your tag

Step-19: Click on the ‘Triggers‘ link and then click on the ‘New‘ button to create a new trigger.

click on the ‘New‘ button to create a new trigger

Step-20: Name the new trigger ‘gtagApiGet‘ and then choose the trigger type to ‘Custom Event‘:

Name the new trigger ‘gtagApiGet‘

Step-21: Type ‘gtagApiGet‘ in the ‘Event Name’ text box and then click on the ‘Save‘ button:

Type ‘gtagApiGet‘ in the ‘Event Name text

Step-22: Click on the ‘Variables‘ link and then click on the ‘New‘ button under the ‘User-Defined Variables‘ section:

click on the ‘New‘ button under the ‘User Defined Variables‘ section

Step-23: Name the new variable ‘Return Client ID‘ and then set the variable type to ‘Data Layer Variable‘:

Name the new variable ‘Return Client ID‘

Step-24: Type ‘gtagApiResult.client_id‘ in the ‘Data Layer Variable Name’ text box and then click on the ‘Save‘ button:

Type ‘gtagApiResult.client id‘ in the ‘Data Layer Variable Name text

Step-25: Click on the ‘Tags‘ link and then click on the ‘New‘ button to create a new tag:

Click on the ‘Tags‘ link

Step-26: Name the new tag ‘Send client id to GA4 test property‘ (or whatever best works for you) and then select ‘Google Analytics: GA4 Event‘ as the tag type:

Name the new tag ‘Send client id to GA4 test property‘

Step-27: Enter your measurement ID:

Enter your measurement ID

Step-28: Type ‘get_user_data‘ in the ‘Event Name‘ text box:

Type ‘get user data‘ in the ‘Event Name‘ text

Step-29: Click on the ‘User Properties‘ drop-down menu:

Click on the ‘User Properties‘ drop down menu

Step-30: Click on the ‘Add Row‘ button:

Click on the ‘Add Row‘ button

Step-31: Type ‘client_id_custom‘ in the ‘Property Name‘ text box and ‘{{Return Client ID}}.‘ in the ‘Value‘ text box:

Type ‘client id custom‘ in the ‘Property Name‘ text

Note: Make sure that you add the dot . after the {{Return Client ID}} variable to force GA4 to treat the value of this variable as a string and not a number.

Step-32: Click on the ‘Choose a trigger’ button:

Click on the ‘Choose a trigger button

Step-33: Click on ‘gtagApiGet‘ trigger:

Click on ‘gtagApiGet‘ trigger

Step-34: Click on the ‘Save‘ button to save your new tag:

Click on the ‘Save‘ button to save your new tag

Step-35: Click on the ‘Preview‘ button to preview your GTM container:

Click on the ‘Preview‘ button to preview your GTM container

You should now be automatically redirected to a new tab in your web browser. 

Step-36: Enter your website address and then click on the ‘Connect‘ button:

Enter your website address and then click on the ‘Connect‘ button

You should now be automatically redirected to a new tab in your web browser which shows your website content. 

Step-37: Navigate back to your Tag Assistant window and then click on the ‘Continue‘ button:

Navigate back to your Tag Assistant window

You should now be able to see the ‘gtagApiGet’ event listed in the event list and the tags ‘Send client id to GA4 test property‘ & ‘Gtag get api‘ listed under the ‘Tags fired’ section:

You should now be able to see the ‘gtagApiGet event listed in the event list

Step-38: Navigate to the ‘DebugView‘ report of your GA4 property:

Navigate to the ‘DebugView‘ report of your GA4 property

Step-39: Find and click on the user property named ‘client_id_custom= ……‘:

Find and click on the user property named ‘client id custom 1

Step-40: Find and click on the user property named ‘client_id_custom‘:

Find and click on the user property named ‘client id custom‘

You should now be able to see the captured client ID:

You should now be able to see the captured client ID

Step-41: Navigate back to Google tag assistant window and then close it by clicking on the cross button at the top left-hand side:

close it by clicking on the cross button

Step-42: Click on the ‘Stop debugging’ button:

Click on the ‘Stop debugging button

Step-43: Navigate back to your GTM account and then click on the ‘Submit‘ button to publish your container:

click on the ‘Submit‘ button to publish your container

Step-44: Enter your container version name and then click on the ‘Publish‘ button:

Enter your container version name and then click on the ‘Publish‘ button

That’s how you can create and pass a user scope custom parameter along with an event.

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

About the Author

Himanshu Sharma

  • Founder, OptimizeSmart.com
  • Over 15 years of experience in digital analytics and marketing
  • Author of four best-selling books on digital analytics and conversion optimization
  • Nominated for Digital Analytics Association Awards for Excellence
  • Runs one of the most popular blogs in the world on digital analytics
  • Consultant to countless small and big businesses over the decade