How to Send User ID to Google Analytics
Tracking users across different devices can feel like trying to solve a puzzle. The same person might visit your site on their phone during their morning commute, browse on a tablet during lunch, and finally make a purchase on a desktop computer in the evening. This article will show you exactly how to connect those dots by setting up User-ID in Google Analytics 4, giving you a complete picture of your user journeys.
What is the User-ID in Google Analytics 4?
In Google Analytics 4, the User-ID is a unique identifier that you create and assign to your logged-in users. Unlike the default anonymous identifiers like the client ID (which tracks a specific browser or device), the User-ID follows a single person no matter how or where they access your site. Think of it as a permanent passport for each of your users once they sign in.
Each time a user logs into your website or app, you pass this unique ID along with their activity data to Google Analytics. GA4 then uses this ID to stitch together all of their sessions from different devices into one cohesive story. It's the key to moving beyond anonymous device-level data and understanding the true, cross-platform behavior of your most engaged audience.
It's important to remember a critical rule: the User-ID must not be personally identifiable information (PII). This means you should never use an email address, username, or real name as the User-ID. Instead, it should be a non-human-readable string of numbers and letters, like "12345XYZ," generated by your backend system.
The Benefits of Using User-ID in Your Analytics
Setting up User-ID isn't just a technical exercise, it fundamentally changes the quality of your data and the insights you can pull from it. Here’s why it’s worth the effort.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
1. Get a Truly Accurate User Count
Without User-ID, Google Analytics sees one person on three different devices as three different users. Your "Total Users" metric is inflated because it’s really counting browsers, not people. By implementing User-ID, you de-duplicate these instances. That morning phone session and evening desktop purchase are correctly attributed to one person, giving you a precise measure of your actual audience size.
2. Map the Full Cross-Device Customer Journey
This is arguably the most powerful benefit. You can finally answer questions like:
- Do users typically discover our products on mobile and convert later on desktop?
- How many touchpoints does a logged-in user have before making a purchase?
- Which content do users engage with on their phone versus their work computer?
Understanding these paths helps you optimize your marketing touchpoints, improve user experience, and attribute conversions more accurately. You start seeing the full narrative instead of disconnected chapters.
3. Enhance Audience Segmentation and Personalization
When you have a complete history of a logged-in user's behavior, you can create much more effective audience segments. For example, you can build audiences for Google Ads based on users who placed an item in their cart on mobile but didn't check out on desktop. This allows for hyper-relevant retargeting and opens the door for delivering personalized content and offers directly on your site based on their holistic behavior.
Before You Start: What You Need
Before diving into the implementation, make sure you have a couple of things in place. Planning this out will make the process much smoother.
- A System to Generate a Unique User ID: Your website’s authentication or backend system needs to be able to generate and assign a unique, non-personally identifiable ID to every user who creates an account or logs in. This ID must be persistent – it should be the same for that user every single time they log in. This typically comes from a user ID in your database.
- Access to Your Website's Code or Google Tag Manager: You'll need to add a small snippet of code to your site. The easiest and most flexible way to do this is with Google Tag Manager (GTM). If you don't use GTM, you'll need the ability to edit the code of your website directly.
- A Google Analytics 4 Property: This guide is specific to GA4. If you haven't migrated from Universal Analytics yet, you'll need to set up a new GA4 property first.
How to Implement User-ID Using Google Tag Manager
Google Tag Manager is the recommended method for most marketing and analytics professionals. It keeps your tracking code organized and allows you to make changes without waiting for a developer. Let’s walk through the process step-by-step.
Step 1: Push the User ID to the Data Layer
The first step happens on your website. After a user logs in, your developer needs to add a snippet of JavaScript that pushes their unique User-ID to the data layer. The data layer is a temporary information hub that your website uses to pass data to Google Tag Manager.
Have your developer add the following code so it fires on every page after a user has successfully logged in:
window.dataLayer = window.dataLayer || [],
window.dataLayer.push({
'user_id': 'REPLACE_WITH_DYNAMIC_USER_ID' // E.g., '67890def' from your database
}),In this snippet, REPLACE_WITH_DYNAMIC_USER_ID should be dynamically replaced with the actual unique ID for the logged-in user from your system.
Step 2: Create a Data Layer Variable in GTM
Now that the User-ID is being sent to the data layer, you need to tell GTM how to catch it and store it.
- Inside your Google Tag Manager container, navigate to Variables in the left-hand menu.
- Under "User-Defined Variables," click New.
- Name your variable something clear, like
dlv - user_id. - Click on Variable Configuration and choose Data Layer Variable as the variable type.
- In the "Data Layer Variable Name" field, enter
user_id. This must match the key you used in the data layer push from Step 1 exactly. - Leave the other settings as default and click Save.
You’ve now created a variable in GTM that holds the value of the user's ID whenever it’s available in the data layer.
Step 3: Send the User ID to GA4
The final step is to attach your newly created variable to your GA4 configuration. This ensures the User-ID is sent along with all the tracking data.
- Navigate to Tags in the left-hand menu.
- Find and click on your main Google Analytics: GA4 Configuration tag. (If you don't have one, you'll need to create it first.)
- Click on Tag Configuration.
- Expand the Fields to Set section.
- Click Add Row.
- For the "Field Name," enter
user_id. - For the "Value," click the small lego brick icon and select your newly created variable:
{{dlv - user_id}}. - Save your tag.
And that’s it! The next time your GA4 Configuration tag fires on a page where a user is logged in (and the user_id is in the data layer), GTM will automatically attach it to the data sent to Google Analytics.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Alternative Method: Implementing User-ID with gtag.js
If you aren't using Google Tag Manager, you can still implement User-ID by modifying the gtag.js (Global Site Tag) snippet on your website directly.
On every page where a user is logged in, you need to modify your main GA4 config line to include the user_id parameter.
Your developer should modify this code on your site:
gtag('config', 'G-YOUR_MEASUREMENT_ID', {
'user_id': 'REPLACE_WITH_DYNAMIC_USER_ID'
}),Make sure to replace G-YOUR_MEASUREMENT_ID with your actual Measurement ID from GA4, and REPLACE_WITH_DYNAMIC_USER_ID with the actual user's ID. This authenticated config line should replace the standard one for any visitor who is signed in.
Verify That Your Setup Works
Never assume your tracking is working correctly. Always verify it. Here are two ways to confirm your User-ID is being sent properly.
1. Use GA4 DebugView
DebugView is a real-time report that shows you events as they come in from your browser. It’s perfect for testing new setups.
- In GTM, enter Preview mode for your container. This will open a new tab with your website.
- Log into your website to trigger the User-ID function.
- In your GA4 property, navigate to Admin > DebugView.
- You should see events streaming in from your device. Click on an event like
page_vieworsession_start. - In the "Parameters" tab, look for a
user_idparameter. You should also see it listed under "User Properties" in the top right. If you see your dynamically generated ID, it’s working!
2. Check the Reporting Identity Setting
Google Analytics needs to know that it should prioritize User-ID when stitching sessions together. You can check this in the admin settings.
- In GA4, navigate to Admin > Reporting Identity.
- Select the Observed option. This tells GA4 to use the following hierarchy for identifying users: first User-ID, then Google Signals, then Device ID. This is the best practice for getting the most accurate reporting.
- Give it a day or two for the data to process. Then, you can head to the Reports > User Attributes > User Explorer report. There, you can click on an individual User ID to see the entire event stream associated with them, confirming that data from different devices is being combined.
Final Thoughts
Setting up User-ID is a critical step towards elevating your data quality from good to great. By moving beyond simple device-level tracking, you gain a unified view of your logged-in users, enabling better analytics, smarter advertising, and more powerful personalization.
Of course, implementing GA4 correctly is just the starting point. When you want to combine that user-level Google Analytics data with your sales data from Shopify, ad spend from Facebook Ads, or deal data from HubSpot, the REAL analysis can begin. Instead of struggling with spreadsheets, we built Graphed to be your AI data analyst. You simply connect your data sources, and then ask questions in plain English like, "create a dashboard showing GA4 sessions and Shopify sales by marketing channel" to get real-time dashboards and answers instantly.
Related Articles
Facebook Ads for Pressure Washing: The Complete 2026 Strategy Guide
Learn the proven Facebook advertising strategies for pressure washing businesses in 2026. Generate more leads with targeted campaigns, compelling creatives, and proper follow-up systems.
Facebook Ads for Caterers: The Complete 2026 Strategy Guide
Learn how to run effective Facebook ads for caterers in 2026. This complete guide covers campaign structure, creative requirements, budget allocation, and timeline for results.
Facebook Ads for Mechanics: The Complete 2026 Strategy Guide
Learn how to use Facebook ads for mechanics to fill your service bays with high-value customers. Complete targeting, offers, and creative strategy for 2026.