Skip to content

Identifying users

Tell the library who a signed-in user is, so their events from every visit and device belong to one person.

Every visitor starts out anonymous, with a random ID kept in their browser. When you identify them, you give that person your own ID for them. From then on their events, past and future, belong to one person you can look up, and their activity on other devices joins up once they sign in there too.

Call identify when you know who it is

Call identify as soon as your site knows who the user is: after they sign up, after they sign in, and on page loads where they are already signed in.

js
myjourney.identify("user_123", {
  email: "[email protected]",
  plan: "growth",
});
  • The first argument is the user's ID in your own system, such as their database ID. It must be unique to that user and must not change.
  • The second argument is optional: person properties to set or update.
  • A third, optional argument holds properties to set only if the person does not have them yet.

Calling identify again with the same ID on every page load is fine: the person is not duplicated, and their properties are only sent again when they have changed.

Only an anonymous visitor's earlier events are joined to the user. If one user signs out and another signs in on the same browser, call reset in between, as described below.

Choose the right ID

  • Use an ID that is unique to the user and never changes.
  • Do not use an email address as the ID: people change them. Store the email as a person property instead.
  • Never pass a placeholder such as "anonymous", "guest", "null", "undefined" or "0". Identifying with these is refused, because it would join many different people into one.

Reset when the user signs out

js
myjourney.reset();

reset gives the browser a new anonymous ID, so the next person to use the device is not counted as the one who just left. Call it from your sign-out code.

Identifying with Google Tag Manager

If your site pushes the user's ID to the data layer when they sign in, you can identify them from a Tag Manager tag instead of your site's code. See Identify signed-in users.

Check that it worked

  1. Sign in to your site as a test user.
  2. In the app, open Activity and the Persons tab, and search for the ID you passed.
  3. Open the person to see their properties and the events from before and after they signed in.

If the person is missing, or two people did not join up, look for merge warnings in Event ingestion warnings.

Server-side events

Events you send from your server should use the same ID you pass to identify, so they land on the same person. For anonymous visitors, read the browser's current ID with myjourney.get_distinct_id() and send it to your server.

Can't find what you need? Contact support