Identify Users

Attach a known identity to a visitor

Call identify after sign-in to link the anonymous visitor id to an external user id and profile fields.

Identify a User

Pass a stable external id and an email. The external id should be the same value your own system uses for that user, such as a database id.

import { identify } from "@faststats/react";

await identify("user_123", "[email protected]", {
	name: "Ada Lovelace",
	traits: { plan: "pro" },
});
import { identify } from "@faststats/web";

await identify("user_123", "[email protected]", {
	name: "Ada Lovelace",
	traits: { plan: "pro" },
});

The third argument is optional and accepts a few profile fields.

FieldTypeDescription
namestringThe display name of the user
phonestringA phone number
avatarUrlstringA link to an avatar image
traitsRecord<string, unknown>Any extra attributes you want on the profile

What identify Returns

identify returns a promise that resolves to a boolean. It is false when the call was skipped, for example when the external id or email is empty or when the visitor is in cookieless mode, and true once the call is on its way.

const ok = await identify("user_123", "[email protected]");
if (!ok) {
	// the visitor is cookieless or the input was empty
}

Identify is disabled in cookieless mode because there is no stored identifier to link a profile to. See Consent and Cookieless.

Log Out

When a user signs out, call logout to start a fresh anonymous session so their next activity is not tied to the old profile.

import { logout } from "@faststats/web";

logout();

By default this also resets the anonymous identifier. Pass false if you want to keep the same anonymous id and only rotate the session.

logout(false);

On this page