---
title: "User IDs set too early: engineering solution"
description: "Keep analytics anonymous until authentication confirms a stable identity, then set the canonical User ID."
product: data
token_estimate: 480
---
# User IDs set too early: engineering solution

> For AI agents: a documentation index is available at [/docs/llms.txt](/docs/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

Gate User ID assignment on your application's confirmed authentication state. This keeps anonymous visitors and people on shared devices from inheriting the wrong identity. The change lives in the application or event pipeline, not in Data Assistant. Start from the findings in the [audit](https://amplitude.com/docs/data/data-assistant-user-solutions/early-user-ids-audit).

## Correct the authentication boundary

1. Find every place that initializes Amplitude or assigns an analytics User ID.
2. Remove placeholder values such as `anonymous`, `guest`, `None`, or an empty string. Leave the User ID unset for unknown visitors.
3. Wait until your authentication system returns the canonical account identifier.
4. Assign that value through your Analytics SDK's User ID method before you track the first authenticated action.
5. When a person signs out on a shared device, clear the User ID and generate a new device ID according to the SDK's logout instructions.
6. When your app restores a valid signed-in session, assign the known User ID before it tracks authenticated events.

> **Note:** Identity updates aren't retroactive
>
> This change protects new events. It doesn't separate historical activity that your implementation already sent under an incorrect User ID.

## Validate the fix

Run the [audit](https://amplitude.com/docs/data/data-assistant-user-solutions/early-user-ids-audit) for a new visitor, a returning signed-in person, and two different accounts on the same device. Confirm that each journey crosses the authentication boundary with the intended identity.

Refer to [How Amplitude identifies your users](https://amplitude.com/docs/get-started/identify-users) before you deploy.

