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.
identify(userId, traits?)
Section titled “identify(userId, traits?)”Call identify after a user signs in. Pass your app’s user id or their email:
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.
How visitor maps to user
Section titled “How visitor maps to user”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.
reset() on logout
Section titled “reset() on logout”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:
window.statskit?.reset();useEffect(() => { if (user) { window.statskit?.identify(user.id, { plan: user.plan }); }}, [user]);
function handleLogout() { window.statskit?.reset(); signOut();}// after loginwindow.statskit?.identify(currentUser.email);
// on logoutlogoutButton.addEventListener("click", () => { window.statskit?.reset();});page(path?) for manual pageviews
Section titled “page(path?) for manual pageviews”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:
window.statskit?.page("/checkout/step-2");The signature is statskit.page(path?). With no argument it records the current path.