Skip to content

Reset on logout

When a user signs out, you should call vektis.reset() so any events the next user (or anonymous visitor) generates aren’t attributed to the previous identity.

What reset() does:

  1. Flushes any queued events using the current identity
  2. Clears the in-memory customer_id / user_id
  3. Returns the SDK to the UNINITIALIZED state — call init() again before tracking further events, or call identify() again on the next sign-in
import * as vektis from "@vektis-io/tracker";
await vektis.flush(); // optional but recommended — guarantees the queue ships
vektis.reset();
"use client";
import { useClerk } from "@clerk/nextjs";
import * as vektis from "@vektis-io/tracker";
export function SignOutButton() {
const { signOut } = useClerk();
const handleSignOut = async () => {
await vektis.flush();
vektis.reset();
await signOut();
};
return <button onClick={handleSignOut}>Sign out</button>;
}

The SDK is back in UNINITIALIZED. To resume tracking under a new identity:

// apiKey: load from your framework's public env var — see the per-framework guide.
vektis.init({ apiKey: YOUR_VEKTIS_API_KEY });
vektis.identify({ customer_id: "acct_B2", user_id: "user_456" });

If you only need to switch identities (a user impersonation flow, for example) and don’t need to flush state, calling identify() again with new values is sufficient — reset() is for true sign-out.