How do I set up user ID tracking in GA4?

Applies to: Google Analytics 4 (GA4)
Last updated: May 2025


Problem

You want to consistently track logged-in users across devices and sessions using a unique identifier (e.g., customer ID or account email hash) to unify their activity in GA4.


Solution

GA4 supports User ID tracking, allowing you to send a consistent identifier for authenticated users. You must send the user_id parameter with events and configure GA4 to use User-ID reporting identity.


Step-by-Step Guide

Part 1: Send the User ID

You need to pass a unique user_id value when the user is logged in. This must be done in your GA4 configuration tag or global site tag.

Using gtag.js:

gtag('config', 'G-XXXXXXXXXX', {
'user_id': 'USER_12345'
});
  • Replace 'USER_12345' with a real identifier (e.g., a customer ID from your authentication system).
  • This code should only run when the user is authenticated.

Using Google Tag Manager:

  1. Create a new User ID variable in GTM:
    • Go to Variables > New
    • Use a JavaScript Variable, First Party Cookie, or Data Layer Variable to capture the User ID
  2. In your GA4 Configuration tag, under Fields to Set, add:
    • Field Name: user_id
    • Value: Your user ID variable
  3. Save and publish your GTM container

Part 2: Enable User-ID Reporting in GA4

  1. Go to https://analytics.google.com
  2. Select your GA4 property
  3. Click Admin > Reporting Identity
  4. Choose Blended or Observed:
    • Blended (recommended): Combines user_id, device ID, and modeling
    • Observed: Prioritizes user_id exclusively

Blended ensures fallback tracking when the user is anonymous.


Testing Your Implementation

  • Use Realtime and DebugView in GA4 to confirm the user_id is being sent
  • Visit the site as a logged-in user and trigger a page view or event
  • In User Explorer (Explore > User Explorer), look for activity tied to user_id

Notes

  • GA4 does not expose individual user IDs in reports, but you can analyze user behavior based on the ID internally (e.g., using BigQuery)
  • Use hashed or anonymized IDs to protect user privacy
  • The user_id must remain consistent and stable, and not PII (e.g., don’t use raw email addresses)