On this page

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

Anonymous activity lost at login: engineering solution

Preserve the anonymous device ID when you assign the stable User ID at login. Amplitude uses that relationship to join the earlier anonymous activity with the known profile. Data Assistant can't repair a relationship that was never sent, so the fix belongs in the login flow. Start from the findings in the audit.

Update the login flow

  1. Keep one initialized Analytics SDK instance across the anonymous and authenticated parts of the session.
  2. Don't regenerate or replace the device ID during login.
  3. After authentication succeeds, set the canonical User ID through the SDK before you track the next event.
  4. If you use the Identify API instead of a client SDK, send an identification object that contains the existing device_id and the newly known user_id. Follow the Identify API request requirements.
  5. Keep sending the same canonical User ID on later authenticated events and on other devices.

Don't change one established User ID into another

Changing a non-null user_id creates another user. This workflow joins an anonymous device to a known User ID. It doesn't merge two established User IDs.

Validate the fix

Repeat the audit. Check the raw event immediately before login and the first event after login. They should share the same device_id, and the event after login should carry the canonical user_id.

Refer to Track unique users for the identity sequence Amplitude expects.

Was this helpful?