Sub topic 6
How GA4 recognizes a user: client ID and User-ID
This chapter assumes you know what a GA4 event and event parameter are, and that you can read basic JavaScript (gtag) and SQL. It covers the identifiers GA4 uses to decide that two events came from the same person, and what happens when that decision is wrong.
Why identity is a separate question
GA4 stores events. A "user" is not a record that GA4 keeps. It is a label attached to each event, and reports group events by that label. If two events carry the same label, GA4 counts one user. If they carry different labels, GA4 counts two, even when one human caused both.
GA4 uses two kinds of label: an identifier it generates (the client ID on the web, the app instance ID in apps) and an identifier you supply (the User-ID).
The client ID: a device-level identifier
On the web, the GA4 tag creates a random identifier the first time it runs in a browser. It stores the identifier in a first-party cookie named _ga. The tag then sends the identifier with every event as the client ID.
Properties of the client ID:
- It identifies a browser profile on a device, not a person.
- The same person on a phone and a laptop has two client IDs.
- Clearing cookies, using a private window, or switching browsers creates a new client ID.
- The cookie's default lifetime is two years, and it is renewed when the visitor returns.
- Some browsers shorten the lifetime of cookies set by JavaScript. Safari's tracking protection, for example, can cap them at seven days. A returning visitor can then look like a new user.
In mobile apps, the equivalent is the app instance ID, which the Firebase SDK generates on install. Reinstalling the app produces a new one.
In the BigQuery export, both appear as user_pseudo_id. The word "pseudo" is accurate: it is a stand-in for a user, not a user.
The User-ID: an identifier you control
The User-ID is a string your own system assigns, usually the primary key of a signed-in account. You send it as the user_id parameter. GA4 then has a stable label that survives across devices and cookie resets, as long as the person signs in each time.
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
// Anonymous visitor: only the client ID identifies them
gtag('config', 'G-XXXXXXXXXX');
// Call this after your site confirms a successful sign-in
function onSignIn(accountId) {
gtag('config', 'G-XXXXXXXXXX', {
user_id: accountId // for example 'u_12345'
});
}
// Call this on sign-out so later events are not tied to the account
function onSignOut() {
gtag('config', 'G-XXXXXXXXXX', {
user_id: null
});
}The client ID is still sent when a User-ID is present. GA4 therefore holds both identifiers on each event after sign-in. That is what lets it connect pre-login and post-login activity from the same device.
Rules for a good User-ID
- It must be unique per person. Do not reuse values or recycle IDs.
- It must not be personal data such as an email address, phone number, or name. Google's terms prohibit sending personally identifiable information. Use an opaque internal ID, or a salted hash only if you understand the privacy implications.
- It must be the same value on every device and platform. If your website uses
u_12345and your app uses12345, GA4 will see two people. - Send it on every event after sign-in, not only on the sign-in event. Events without it are treated as anonymous.
How the two identifiers combine: reporting identity
GA4 does not simply pick one. A property-level setting called the reporting identity decides which identifiers are used to count users in reports.
| Reporting identity | Identifiers used, in order | Typical effect |
|---|---|---|
| Blended | User-ID, then Google signals, then device ID, then behavioral modeling | Lowest user counts, best cross-device view, fills gaps with modeling |
| Observed | User-ID, then Google signals, then device ID | Same as blended without modeling |
| Device-based | Device ID only | User-ID is ignored for counting, and numbers match the raw client IDs |
Google signals is an optional feature that uses data from signed-in Google users who have turned on ads personalization. It depends on consent and thresholds, so it can make numbers differ between properties.
The diagram shows how an identity is resolved for one event under blended or observed identity.
A worked scenario
Ana visits your shop on her laptop and browses three pages. She signs in, buys something, then opens your app on her phone and signs in there.
- Laptop events before sign-in carry client ID
A1, with no User-ID. - Laptop events after sign-in carry
A1plusu_12345. - Phone events carry app instance ID
B7plusu_12345.
Under device-based identity, GA4 reports two users, A1 and B7. Under blended or observed identity, GA4 reports one, because the User-ID joins the phone to the laptop. GA4 can also associate the laptop's pre-login events with her, because A1 later appeared together with u_12345.
This association happens in the reports. The raw events keep what was actually sent. A pre-login event still has no user_id in the BigQuery export, so any export query that counts users must do its own stitching.
Setting the User-ID through other routes
gtag('config', ...) is not the only route. You can also:
- Set the
user_idas a field in Google Tag Manager's GA4 configuration tag or settings variable. - Send
user_idin each event's parameters, which is useful for single-page apps whereconfigis called only once. - Include
user_idin the Measurement Protocol payload for server-side events, together with the sameclient_idthe browser used. Without the matchingclient_id, the server event cannot be tied to the browser session.
Checking what GA4 received
The export lets you compare the two identifiers directly. This query shows, per day, how many device IDs were seen, how many distinct User-IDs were seen, and how many events were sent without a User-ID.
SELECT
event_date,
COUNT(DISTINCT user_pseudo_id) AS device_ids,
COUNT(DISTINCT user_id) AS signed_in_users,
COUNTIF(user_id IS NULL) AS events_without_user_id
FROM `my-project.analytics_123456789.events_*`
WHERE _TABLE_SUFFIX BETWEEN '20240101' AND '20240131'
GROUP BY event_date
ORDER BY event_date;A large gap between device_ids and signed_in_users is normal when most visitors are anonymous. A sudden rise in events_without_user_id for a signed-in-only section of your site suggests the user_id is not reaching every event.
Common errors
- Setting the User-ID too late. If your tag fires before the sign-in state is known, the first events of each page load go out without it. Delay or re-fire the configuration once the account ID is available.
- Sending an email address. This breaks policy and can lead to data deletion. Use an internal ID.
- Different IDs per platform. Web and app must share the same value.
- Shared devices. If you never clear
user_idon sign-out, the next person on that browser inherits the previous person's identity. - Expecting retroactive changes. Changing the reporting identity affects how reports are computed over the data you already have, but it does not rewrite the stored events. Setting up a User-ID today does not add it to last month's events.
- Cross-domain journeys. If a visitor moves from
shop.example.comtopay.example.orgwithout cross-domain linking, the second domain creates a new client ID. The visitor becomes a second user, and a new session starts.
Choosing an approach
Use the client ID alone if your site has no accounts or you cannot send a stable internal ID. Add the User-ID when you have sign-in and care about cross-device journeys, or when you want to join GA4 data with your own customer tables. Prefer blended identity for the broadest view. Choose device-based identity when you need numbers that can be reproduced exactly from raw user_pseudo_id values in BigQuery.
Exercise
A customer browses your site on a laptop as an anonymous visitor, then signs in on the same laptop, then signs in on the mobile app. Your property uses blended reporting identity and your tagging sends the same user_id on both platforms after sign-in. How many users does GA4 report for this customer, and how many user_pseudo_id values appear in the BigQuery export?
Show answer
GA4 reports one user, because the User-ID joins the laptop and app activity, and the laptop's pre-login events share a client ID with its post-login events. The export contains two user_pseudo_id values: one for the laptop browser and one for the app instance. The pre-login events have no user_id in the export.
Exercise
After a release, the query from this chapter shows events_without_user_id doubling, but only for pages behind the login. What is the most likely cause, and where would you look first?
Show answer
The user_id is no longer attached to every event on those pages. Check whether the GA4 configuration or the user_id parameter now fires before the sign-in state is known, for example after a tag or single-page-app routing change, and make sure user_id is set again after the account ID is available.