User IDs in Google Analytics 4 (GA4) track users across sessions. GA4 assigns users a unique client ID on the web (stored in a cookie) and an app-instance ID for mobile apps.
However, the IDs that GA automatically assigns can’t be shared across devices, browsers, and apps. So GA will overcount users who visit using different browsers or devices.
A single user visiting your site using an iPhone one day and a laptop the next or an Android app and a mobile web browser, or any other combination of devices and browsers is treated as two separate users.
GA4 has a user ID feature that allows site owners to set their own user ID{: rel=”noreferrer”}. By assigning IDs to signed-in users, website owners can unify a user’s journey and get more accurate user counts.
Google Signals and cross-device tracking
With Google Signals, GA4 can recognize user interactions across different devices and browsers if they have signed in to a Google account and have enabled ad personalization.
Before February 2024 you could select reporting identities in your GA4 property settings that used data from Google Signals. Now that’s no longer an option.
While that may sound like a bad thing, Signals data only applied to a subset of data and often caused thresholding in reports.
Benefits of setting your own User ID in GA4
Setting an ID isn’t worth it for every site. Sites with logged-in users that have long, cross-device journeys will benefit the most. The benefits for those sites are:
- Prevent Double Counting: With user IDs, you can prevent double counting of users who visit your site using multiple devices or browsers. This ensures that your analytics data more accurately reflects your real-world user count.
- Enhanced Attribution: By joining user sessions across devices you get richer attribution data. This allows you to measure the impact of your marketing efforts and optimize your campaigns accordingly.
- Better insight into user journeys: While you can’t use PII, you can use a user ID that allows you to tie up your web data with your customer database/CRM. That, coupled with cross-device data should give you a more holistic story about users’ engagement with your site.
If your site only has logged logged-out users you won’t be able to tie cross-device journeys. In this case, a device identifier like a cookie will provide the same data as setting your own user ID.
User overlap across devices in the Tech overview report:
How User ID tracking works in GA4
When a logged-out user arrives at your site, they are automatically assigned a unique device ID by GA.
When the user signs in and the user ID is set, their previous event data in that session is associated with the new user ID that was set at log-in.
If that logged-in user then logs out, subsequent events are no longer associated with the user ID and the device ID is used instead.
So events before user login get associated with user ID data set later in the session, but events after log-out do not.
How to set up User ID tracking in Google Analytics 4
Best Practices for Assigning User IDs in GA4
Let’s first talk about some guidelines for the user ID field:
- Do not use Personally Identifiable Information (PII) as your user identifier. Google’s privacy policy prohibits the use of an email address, IP address, physical address, or any other form of PII.
- Values should not exceed 256 characters in length.
- If the user doesn’t have an assigned ID, you need to return a value of ‘undefined’. If you set an actual value like ‘none’ the tracking hit will be discarded.
How to send a user ID to Google Analytics
To send a user ID to GA4 you need i) a way to access the user ID ii) to store the user ID in a variable in Google Tag Manager (GTM) iii) and to add the user ID to your config and event tags in GTM.
i) Getting access to the user ID
I strongly recommend you work with a developer to add the user ID to the data layer. Setting the user ID is not something you want to hack or do inconsistently as it will negatively impact your user counts and other metrics.
An acceptable alternative is to read the user ID from a first-party cookie if you have it stored in one. This is easily done using the first-party cookie variable in Google Tag Manager.
You should send the user ID with every event (including pageviews) so it needs to be available on the page before your tags fire. Set it above the GTM code in the head of your page.
If you set it above the standard GTM code, you must first initialize the data layer. Be careful not to do this if you place your code below the standard GTM code.
<script>
//First, initialize the data layer. NB - only do this if you are placing the code above the standard GTM code
window.dataLayer = window.dataLayer || [];
//then push your user ID to the data layer
dataLayer.push({ ‘userID’: ‘1234’ }); //replace 1234 with a variable that holds your user ID
</script>
You can also pair the user ID with a user authentication event like login. Here’s the code snippet to do that:
<script>
dataLayer.push({
‘userID’: ‘1234’, //replace 1234 with a variable that holds your user ID
‘event’: ‘login’
});
</script>
ii) Storing the user ID in a variable in Google Tag Manager
- Create a variable to store the user ID in Google Tag Manager:
- Log in to your Google Tag Manager account.
- Go to the Variables section and click on “New”.
- Choose the Variable type as “Data Layer Variable”.
- Set the same variable name that you used in the code in the step above. In this case, it’s “userID”.
iii) add the user ID to your config and event tags in GTM.
Add the user ID to your GA4 config tag:
- If you don’t already have one, add a new ‘Google tag: configuration settings’ variable. If you do have it, edit your existing one.
- Add your user ID to the variable by entering user_id as the Config Parameter and the name of your data layer variable as the Value.
- Add the settings variable to your config tag:
Add the user ID to your GA4 event tags:
- If you don’t already have one, create a ‘Google Tag: Event Settings’ variable. If you do have it, edit your existing one.
- Add your user ID in the variable by entering user_id as a User Parameter and the name of your data layer variable as the Value. Make sure to use ‘Google Analytics User Properties’ rather than an Event Parameter.
- Now add the event settings variable to your event tags:
Lastly, you will want to use preview mode in GTM to make sure everything is working as expected for both your config and event tags:
How to see the User ID in GA4 reports
User IDs are quite hidden in Google Analytics. In Universal Analytics people got around this by adding a custom dimension with the User ID.
That’s not recommended in GA4. Storing the User ID in a custom dimension will result in cardinality{: rel=”noreferrer”} issues causing your reports to be less accurate.
To see the User ID in GA4 reports, you can add it as a secondary dimension in the standard reports or create a User Exploration in the Explore (custom reports) section.
i) Using a secondary dimension to see the user ID
This is a bit hacky but it works (at least at the time of writing).
- Navigate to the GA4 interface and select a detail report.
- Click on the plus icon above the table to add any secondary dimension. I’m adding Country to the Events report here:
- In the URL in your browser find “country”. It’s towards the end of the URL:
- Delete “country” and replace it with “appInstanceId”. You will now see ‘Effective user ID’ added as a secondary dimension in your report.
ii) In the User Explorer report:
- Navigate to the GA4 interface and click on “Explore” in the left-hand menu.
- Scroll right on the Template gallery and select “User explorer”.
- In the report, you’ll see the “Effective user ID” dimension along with a count of events, sessions, and other metrics.
- If you click on an individual user ID, a tab opens showing individual events for that user along with a summary card of their top events.
Create remarketing audiences for Google Ads with the user ID feature
The User ID feature helps in unifying a user’s journey across multiple devices and sessions. This means you can create GA4 audiences{: rel=”noreferrer”} that target users based on their interactions across different devices. Cross-device tracking should make your lists more accurate and relevant.
If your GA4 and{: rel=”noreferrer”}Google Ads accounts are linked{: rel=”noreferrer”}, remarketing audiences created using User IDs will be available in your Google Ads shared library.
User IDs in BigQuery
From the GA UI, you might think there is just one user ID field. But, there are two. The client ID/ app-instance ID and the user ID field.
This is obvious if you look at BigQuery.
user_pseudo_id in this BigQuery screenshot is the client id, the website owner hasn’t set a user ID for this user
The main difference between the User ID and User Pseudo ID fields in GA4 lies in how they are generated and utilized.
User IDs are manually created and assigned by you to identify and track individual users across devices and sessions, while User Pseudo IDs are automatically generated by GA4 to temporarily track users within a session when a User ID is not available.
Issues with setting the User ID in GA4
Setting a user ID results in ‘direct’ traffic attribution
If you set a user ID mid-session it can overwrite your original traffic attribution and set it as ‘direct’. By traffic attribution, I mean the source/medium values GA assigns your traffic.
If a user arrives at your site by clicking an organic Google search link and you set their user ID midway through their session this bug causes their session source to be set as direct.
Increases in sessions and users
Setting a user ID can increase your session and user counts.
If you assign a user ID midway through a session and then a user later logs out:
- Events before the user ID was set, will get assigned a user ID
- Events after the user logs out, will not get assigned a user ID
In this scenario, you have two users and sessions instead of one.
Setting the wrong value for users without a user ID results in no tracking
If a user doesn’t have an assigned ID, you need to return a value of ‘undefined’. In Universal Analytics it was OK to give these users a value of ‘none’ or some other string. That’s not the case in GA4.
If you give users without an ID a value of anything other than ‘undefined’ the tracking hit will be discarded. That can lead to sessions not being tracked at all for users without IDs.
User Privacy and User IDs
User IDs can potentially contain personally identifiable information (PII) such as email addresses or usernames. Website owners must be careful not to collect PII in user IDs and should respect user consent choices.
Conclusion
User IDs in Google Analytics 4 are a powerful tool for accurate user tracking, preventing double counting, personalizing user experiences, and enhancing attribution. By implementing User IDs and following the proper steps, you can unlock these benefits and gain deeper insights into your audience’s behavior. This will help you make data-driven decisions and optimize your marketing strategies for better results.
##
##