How to Track User ID in Google Analytics
Tired of seeing inflated user counts and broken customer journeys in Google Analytics? You're not alone. By default, Google Analytics tracks devices, not people. This means when someone visits your site on their phone and later on their laptop, GA4 counts them as two separate users. This tutorial will show you how to fix this by implementing User ID tracking, giving you a crystal-clear, accurate view of how real people interact with your business across all their devices.
What is User ID Tracking in Google Analytics?
User ID tracking is a Google Analytics feature that lets you associate a user's activity with a single, persistent ID that you provide. Instead of relying on the default browser cookie (known as the Client ID) which is tied to a specific device, the User ID links all of a user's sessions and actions back to them, no matter which device they use.
Think of it like this:
- Client ID (Default): Imagine a library that only tracks library cards. If you have a card for the downtown branch and another for the uptown branch, the library's system thinks you are two different people. It can't see that you are the one checking out books from both locations.
- User ID (What you want): Now, imagine the library gives you a single member ID. It doesn't matter which library card you use, a librarian can look up your ID and see your entire borrowing history across all branches. That's what the User ID does for your website analytics.
When a user logs into your website or app, you assign them a unique, non-personally identifiable ID (like user-54321). You then send this ID to Google Analytics. From that point on, GA will stitch together that user's behavior from their phone, tablet, and desktop into one unified user journey.
One crucial note: Google has a strict policy against sending Personally Identifiable Information (PII) into Analytics. This means you must never use an email address, name, or phone number as the User ID. The ID must be a unique, anonymous string that only makes sense within your own system.
Why User ID Tracking is a Game-Changer
Implementing User ID tracking isn't just a minor tweak, it fundamentally changes the quality and accuracy of your data. Here are the key benefits:
1. Get an Accurate User Count
The most immediate benefit is a more realistic user count. Without User ID, your "Total Users" metric is actually closer to "Total Devices/Browsers". For businesses with an engaged, logged-in user base, this can dramatically inflate your numbers. By de-duplicating users across devices, you get a true measure of your audience size.
2. Understand the Complete Customer Journey
The modern customer journey is messy and rarely happens on a single device. Consider this common scenario:
- Morning: A user sees your Facebook ad on their phone during their commute and clicks through to browse your site.
- Afternoon: Back at the office, they open their laptop, search for your brand directly, and log in to add a few items to their cart.
- Evening: Later at home, they grab their tablet, log in again, and complete the purchase.
Without User ID tracking, GA4 would see this as three separate users performing disconnected actions. The purchase would likely be attributed to "Direct" traffic, and you'd have no idea the Facebook ad on their phone started the entire process. With User ID, GA4 connects all three sessions, correctly showing the full C-to-C (click-to-conversion) path and giving credit where it's due.
3. Deeper Analysis of High-Value Users
Who are your best customers? What content do they engage with most? How long does it really take for a registered user to make their second or third purchase? User ID allows you to answer these questions with confidence. You can create segments of your most valuable logged-in users and analyze their behavior over their entire lifecycle, not just an isolated session. This is invaluable for improving retention and increasing customer lifetime value.
Now that you understand the "why," let's get into the "how." Follow these steps to get User ID tracking up and running.
How to Set Up User ID Tracking in GA4 (Step-by-Step)
Setting up User ID tracking involves three main parts: generating the ID on your website, pushing it to the data layer, and configuring Google Tag Manager (GTM) to send it to GA4. Don't worry if this sounds technical, we'll break it down.
Step 1: Generate a Unique, Persistent, and Non-PII User ID
This first step happens on your website's backend and needs to be handled by your development team. The requirement is simple: whenever a user creates an account or logs in, your system must generate a unique ID for them.
This ID must be:
- Unique: No two users should ever have the same ID.
- Persistent: The same user must receive the same ID every time they log in, regardless of the device.
- Non-PII: As mentioned before, it cannot be an email, username, or anything that could directly identify the person. Database IDs are a great choice (e.g.,
1138,customer_90210).
Step 2: Push the User ID to the Data Layer
The data layer is a JavaScript object on your site that acts as a middleman, holding information you want to pass to tools like Google Tag Manager. Once a user successfully logs in, your developer needs to add a small snippet of code that pushes their new User ID to this data layer.
Here’s what the JavaScript would look like:
<script>
// This code must run AFTER a user successfully logs in
window.dataLayer = window.dataLayer || [],
window.dataLayer.push({
'event': 'login_success',
'user_id': 'THE_UNIQUE_USER_ID_FROM_YOUR_SYSTEM' // This should be a dynamic variable
}),
</script>The THE_UNIQUE_USER_ID_FROM_YOUR_SYSTEM is a placeholder. Your developer will replace it with the dynamic variable that holds the actual ID from your database.
Step 3: Configure Google Tag Manager
With the User ID now in the data layer, we need to instruct GTM to grab it and pass it along to Google Analytics.
A. Create a Data Layer Variable in GTM
First, we need to tell GTM how to read the user_id from the data layer:
- In your GTM container, navigate to Variables in the left-hand menu.
- Under "User-Defined Variables," click New.
- Give your variable a name, like dlv - user_id.
- For "Variable Configuration," choose Data Layer Variable.
- In the "Data Layer Variable Name" field, enter
user_id. This must match the key you used in the data layer push code exactly. - Click Save.
B. Update Your GA4 Google Tag
Next, we need to tell your main GA4 tag to include this new User ID with every bit of data it sends:
- In GTM, navigate to Tags.
- Click on your primary GA4 tag (it might be called "Google Tag" or "GA4 Configuration").
- Click on Configuration Setting.
- Under "Configuration settings," click Add parameter.
- In the "Parameter name" field, type
user_id. - In the "Value" field, click the lego block icon and select your newly created variable,
{{dlv - user_id}}. - Save your tag.
Step 4: Verify and Publish
Before making your changes live, it’s essential to make sure everything is working correctly.
- In the top right of GTM, click Preview. Enter your website’s URL and connect.
- In the new tab with your website, log into your user account.
- Go back to the GTM Preview tab. You should see your
login_successevent on the left. Click on it. - Now click on a tag that fired after the login, like a Page View or GA4 tag.
- Click on "Variables" in the preview panel and find your
dlv - user_idvariable. It should be populated with the actual User ID. This confirms GTM is receiving the ID correctly.
You can also use the GA4 DebugView (found in the Admin section) to see the user_id parameter being attached to incoming events in real-time. Once you're confident it's working, go back to GTM and click Submit to publish your changes.
Using Your New User ID Data in GA4
It can take 24-48 hours for GA4 to begin processing data with the User ID. Once it does, the first thing you should do is adjust your reporting identity.
Choose Your Reporting Identity
This setting tells GA4 how to de-duplicate users in your standard reports.
- Navigate to Admin in GA4.
- In the "Property" column, click on Reporting Identity.
- Select the Observed option. This method prioritizes the signals in order: 1. User ID, 2. Google Signals, 3. Device ID. This ensures that whenever a User ID is present, it becomes the primary identifier. Save your changes.
Analyzing User Behavior in Explorations
While all of your standard reports will now be more accurate, the true power of User ID data is unlocked in the Explore section.
Let's say you want to trace the steps of your logged-in users. The User explorer report is perfect for this.
- Go to Explore in the left-hand menu and create a new "User explorer" report ("Blank" Template >> select "User explorer" as the Technique).
- Immediately, you'll see a table of individual users identified by their User ID (or Device ID if they're not logged in).
- Click on any "User-ID" stream. You'll now see every single action that user has taken, across every session and device, presented in a chronological timeline. You can see them visit from a mobile ad, add a product to their cart on desktop, and finally purchase a week later, all in one consolidated view. It’s the full, unbridled customer journey.
You can also create segments in other Exploration reports (like Funnel exploration) where the condition is "User has an ID" to compare the behavior of your logged-in audience against unknown visitors.
Final Thoughts
Switching from default device-based tracking to person-based User ID tracking is one of the single most valuable configurations you can make in Google Analytics. It cleans up your data, unlocks true cross-device analysis, and gives you a much more authentic understanding of how people engage with your business over time.
Of course, high-quality tracking is just step one. Turning that complex, cross-platform data into clear, actionable insights is still a major challenge. At Graphed, we help you connect all your tools - Google Analytics, ad platforms like Facebook and Google Ads, your CRM, and e-commerce platforms like Shopify - in a single click. From there, you can ask questions in plain English like, "What’s the full journey of users acquired via paid search this quarter?" and get instant, always-on dashboards built for you automatically. It’s the end of wrestling with reports and the beginning of getting clear answers.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.