Most of your visitors are anonymous, and GA4 identifies them by a cookie per browser. For the visitors who log in, you know more: they are the same person on their phone, their laptop and the office computer. The User ID feature lets GA4 use that knowledge. This guide covers the setup through GTM, the rules, and what it unlocks.
What the User ID Does
When you send a user_id with events, GA4 can link sessions from different devices and browsers that share the same ID, provided the reporting identity includes User ID. User counts become closer to real people, cross-device paths appear, and audiences can include a person on every device they used while logged in.
It does not retroactively link anonymous sessions before login, except within the same browser where GA4 can associate the earlier client ID with the user once the ID appears.
The Rules
- The value must not be personally identifiable: no email, phone, name, username that is an email, or government ID.
- It must be the same value for the same person every time, on every platform.
- It must not appear in URLs or page titles that GA4 collects.
- Do not send it for logged-out visitors.
- Document it in your privacy policy, and respect analytics consent.
A database primary key such as 48213, or a SHA-256 hash of it, is ideal.
Step 1: Push the ID and Properties When Known
On every page where the user is logged in, before the GTM snippet:
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
user_id: '48213',
user_plan: 'pro',
user_customer_status: 'existing',
user_orders_band: '5-10',
user_signup_year: '2024'
});
</script>
On single page apps, push the same keys when the login completes and send a login event, then ensure subsequent virtual page views carry them.
Push user_id as an empty value on logout so GTM does not keep sending the previous user's ID on that browser.
Step 2: Configure the Google Tag
In GTM, open the Google tag. Under Configuration settings, add user_id with value {{dlv - user_id}}. Under Shared event settings or User properties, add each property: plan to {{dlv - user_plan}}, customer_status to {{dlv - user_customer_status}}, orders_band to {{dlv - user_orders_band}}.
GA4 ignores an undefined user_id, so anonymous visitors are unaffected.
Step 3: Reporting Identity
In GA4 Admin, Property settings, Reporting identity, choose Blended, which uses User ID, then Google Signals if on, then device ID, then modelling. Observed is the same without modelling. Device-based ignores User ID entirely.
Step 4: Register User Properties
Under Admin, Custom definitions, create user-scoped custom dimensions for each property: Plan from plan, Customer status from customer_status, and so on. You have 25 user-scoped dimensions.
Step 5: Use It
- Reports: Reports, User, User attributes, Audiences, and any report with a user-scoped dimension added as a secondary dimension.
- Explorations: User explorer shows individual user timelines by User ID or client ID. Cohort explorations by signup month.
- Audiences: Users with plan equals
trialand nopurchasein 14 days, for an upgrade campaign; synced to Google Ads for remarketing. - BigQuery: the
user_idcolumn lets you join GA4 behaviour with your own user table for churn, lifetime value and support analysis.
Cross-Device in Practice
A user reads guides on a phone while logged in, then signs up for a plan on a laptop the next day, also logged in. With User ID and Blended identity, GA4 reports one user, a two-session journey, and attributes the purchase to the phone session's campaign under data-driven attribution. Without it, two users, two journeys, and the purchase attributed to the laptop's direct visit.
Keeping It Out of URLs
Some apps put the user ID in query strings or paths, for example /account/48213. GA4 would store that in page_location, which is acceptable for an opaque ID but not for emails. If your URLs contain emails or names, use a GTM variable to redact them from page_location before the Google tag sends it, or change the URL structure.
Testing
- Log in on the site with GTM Preview open. Confirm the Google tag's configuration shows
user_idand the user properties populated. - GA4 DebugView: select your device; events show a user ID in the header and the user properties in the panel.
- Log out; confirm
user_idis empty on subsequent events. - After a day, the User explorer shows your test user with sessions from two devices if you repeated the login elsewhere.
Common Mistakes
- Sending email or username as the ID.
- Sending the ID on logged-out pages after logout.
- Reporting identity set to Device-based so the ID is never used.
- Properties pushed after the Google tag fired, so the first page view lacks them.
- User properties with personal data such as name or city at a granularity that identifies people.
Outcome
Logged-in customers become one person across their devices in GA4, with attributes you can segment and target by, and a clean join key to your own data in BigQuery, all without putting anyone's identity into analytics.
