Identify Users

Attach a known identity to a visitor

Call identify after sign-in to link the anonymous visitor to a stable external user ID and optional profile data.

Identify a User

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

const identify = useIdentify();
await identify("user_123", "ada@example.com", {
	name: "Ada Lovelace",
	traits: { plan: "pro" },
});
const { $faststats } = useNuxtApp();

await $faststats.identify("user_123", "ada@example.com", {
	name: "Ada Lovelace",
	traits: { plan: "pro" },
});
import { identify } from "@faststats/web";

await identify("user_123", "ada@example.com", {
	name: "Ada Lovelace",
	traits: { plan: "pro" },
});

The external ID is required. Email and all profile fields are optional. You can also pass one object instead of positional arguments.

await identify({
	id: "user_123",
	email: "ada@example.com",
	name: "Ada Lovelace",
	traits: { plan: "pro" },
});

Profile Options

FieldTypeDescription
namestring | nullDisplay name; pass null to clear it
phonestring | nullPhone number; pass null to clear it
avatarUrlstring | nullAvatar URL; pass null to clear it
traitsRecord<string, unknown>Custom profile attributes
traitMode"merge" | "replace"Merge traits by default or replace the trait set
unsetTraitsstring[]Trait keys to remove
aliasesstring[]Additional external IDs for this user

Return Value

identify resolves to true when the request was sent. It returns false if the client is not active, consent is denied, cookieless mode is active, or the external ID is empty.

Identification is disabled in cookieless mode because there is no stored visitor identifier to link to the profile.

Log Out

Call logout after sign-out to rotate the session and, by default, reset the anonymous identifier.

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

logout();

Pass false to keep the anonymous identifier and only reset the session. In React use useLogout; in Nuxt call $faststats.logout().