Google Analytics 4 User ID Tracking

The user ID feature in Google Analytics 4 allows us to count the users accurately and will enable us to measure their activity across different sessions, devices, and platforms. There are three basic requirements for this feature to work. First, we need a unique User ID for each user.

Three User ID Requirements


Second, we will need to send the user ID to GA4. We need a way to get this user ID on our site and pass it to GA4. And finally, we need to configure GA4 to use a User ID in reporting. To get the user ID, we need a mechanism for users to sign in. User ID is called by different names in different organizations. Where we get the User ID depends on the organization and how the website is structured. 

How to get a User ID


It could be a login ID, Customer ID, or record ID. Even an email can be converted into a unique user ID. If the website does not have an option for users to log in but collect email addresses via a form, then we can ask our developers to convert that email address into a unique ID. Generally, a User ID is stored in cookies, session storage, local storage, JavaScript variables, or data layers.

User ID Storage


We might have to ask our developers to help us identify the place where we can find this user ID. In this case, the User ID is available in a global JavaScript variable called User ID. Use Google Tag Manager to pull this user ID and pass it to GA4. 


Every site is different. The User ID might be available in a cookie or a different location. Now that we know where this user ID goes in Google Tag Manager, look at the variable that pulls this information. In Google Tag Manager it is defined a variable called NZ_UserID. JavaScript type variable allows us to pull any JavaScript values from our web pages. This global variable used in the Optizent website is called sitetracking.userid.


The above image provides the Optizent User ID, and the below image provides information about Site Tracking. Go back to Google Tag Manager - we need the variable's name, which stores the user ID. Once done, go ahead and save the variable. Now this variable can be used to pass the user ID over to Google Analytics 4. 


Go to Tags and find the GA4 configuration tag. In this case, it is called the GA4 base tag. We use this tag to send the user ID over to Google Analytics 4. To do that, we need to create a new field name called User ID and pass the user ID value to that field name. So click on Field to set. We might have to expand it to open this section and click on Add Row. So the field name we will use is the User ID. This is the field name predefined by Google Analytics 4 to send the User ID; next is the value we need to pass. So click on the plus and find the variable that contains the User ID(nz_UserID). 


Every time the GA4 base configuration is used, it will pass the User ID value contained in that variable over to the User ID field in Google Analytics 4. Once done, go ahead and click on Save. Next, preview the tag before making it live. Click on Preview, add the website's URL, and click on Connect.


Go to Tag assistant and click on continue. We can see the GA4 base tag gets fired. Click on it, and see User ID gets passed with nz_UserID as value. Scroll down where it says Container Loaded. That's where the base tag gets fired. Click on variables and find nz_UserID. We can see the value that's getting passed over to GA4. Now the tag is ready. Publish it. 



The user ID will be passed from our website to GA4. Once the data is collected in GA4, GA4 will start using that User ID to track the users across the sessions and devices.

Google Analytics 4 help and support

We are here to help you with all your Google Analytics needs. Our team can get you up and running in no time and also train you and your team to save you a lot of time so that you can focus on driving the business outcomes rather than configuring Google Analytics 4.

Online Course - If you want to learn on your own then check out Google Analytics 4 Masterclass

Workshop - We conduct the onsite customized workshop. Reach out to us for more details.

Consulting - Reach out to us for more details.

Leave a Reply

Your email address will not be published.