16 June 2023

How to send User ID in GA

Two birds

In summary

  • User IDs can be sent to Google Analytic 4 (GA4) using Google Tag Manager (GTM)
  • A dataLayer is needed on your site store the ID so that GTM can capture it and send to GA4

What is a User ID?

A user ID is a unique identifier assigned to users on your website. It allows a users’ journey to be unified as they browse your site across different devices. Connecting users across different touch points means your analytics reporting is more accurate.

For a detailed look at user IDs, how they work and their benefits, see User ID in GA4.

How to send User ID to GA4

Step 1
Determine and create a unique ID for each user that will be consistently assigned to them. For example, if you identified email addresses are unique to each customer, you can use the hashed version of a customer’s email address as a User ID. We also recommend using Customer ID in your backend system as the User ID in GA4. Please note each User ID length must be less than 256 characters, and you must ensure User IDs do not contain PII (e.g. original/ unhashed email address).

Step 2
Ask your development team to send the User ID to dataLayer using the below code

1  dataLayer.push({
2    'user_id': '[user_id_value]'
3  });

Step 3
Great! Now we need to set up Google Tag Manager to capture and send this value to GA4. Visit your container in https://tagmanager.google.com/ and go to ‘Variables

Variables in GTM

Step 4
Create a Data Layer Variable to capture User ID from the dataLayer. Scroll down to ‘User-Defined Variables’ and click ‘New

Data Layer Variable in GTM

Step 5
Create a Data Layer Variable to capture User ID from the dataLayer. The Data Layer Variable name is ‘user_id’

Variable Configuration in GTM

Step 6
Now you’re ready to send this Data Layer Variable to GA4. Since you need to send the User ID with every event, we recommend setting the User ID in the global GA4 configuration tag. This way, all event tags based on this GA4 configuration tag will inherit the User ID value when it is available.

Choose your main GA4 configuration tag and add the User ID in the ‘Fields to set’ section.

Configuration tag in GTM

That’s it! Now you can head to GA4 Debug mode to see if User ID is collected as a user property.

Debug mode in GA4

Next steps

If you are interested to learn more about analytics and GMPs, head over to our blog for more articles. You can also sign up to our newsletter to receive new and exciting articles right in your inbox!



About Sophia Vu

Sophia is a data and business analyst, specialising in digital analytics and tagging. In her spare time, she enjoys working on her music skills and enjoying nature.