Skip to content

Identify users

Out of the box, StatsKit tracks anonymous visitors. Calling identify links the anonymous visitor to a known user in your system, so their prior events stitch to that identity.

See identity concepts for how visitors, sessions, and users relate.

Call identify after a user signs in. Pass your app’s user id or their email:

After sign in
window.statskit?.identify("user_123", { plan: "pro" });

The signature is statskit.identify(userId, traits?). Traits are optional properties (plan, role, cohort) attached to the identity.

The tracker holds a persistent statskit_visitor_id from the first pageview, before you know who the visitor is. When you call identify, prior anonymous events stay tied to that same visitor_id, and the server stitches them to the userId you provide. The result: a single journey from first anonymous touch through signup and beyond.

Call reset when a user signs out. It mints a fresh anonymous visitor and session so the next person on that device is not attributed to the previous user:

On sign out
window.statskit?.reset();
Auth effects
useEffect(() => {
if (user) {
window.statskit?.identify(user.id, { plan: user.plan });
}
}, [user]);
function handleLogout() {
window.statskit?.reset();
signOut();
}

SPA route changes fire pageviews automatically. Call page when you want to record a view that is not a real navigation, such as a modal, a wizard step, or a virtual route:

Manual pageview
window.statskit?.page("/checkout/step-2");

The signature is statskit.page(path?). With no argument it records the current path.