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:
- Flushes any queued events using the current identity
- Clears the in-memory
customer_id/user_id - Returns the SDK to the
UNINITIALIZEDstate — callinit()again before tracking further events, or callidentify()again on the next sign-in
import * as vektis from "@vektis-io/tracker";
await vektis.flush(); // optional but recommended — guarantees the queue shipsvektis.reset();Snippets by auth provider
Section titled “Snippets by auth provider”The useAuth() hook exposes signOut. Reset the tracker before signing out:
"use client";
import { useAuth } from "@workos-inc/authkit-nextjs/components";import * as vektis from "@vektis-io/tracker";
export function SignOutButton() { const { signOut } = useAuth();
const handleSignOut = async () => { await vektis.flush(); vektis.reset(); await signOut(); };
return <button onClick={handleSignOut}>Sign out</button>;}Prefer a Server Component or Server Action? Import signOut from @workos-inc/authkit-nextjs and call the tracker reset on the client just before it:
import { signOut } from "@workos-inc/authkit-nextjs";
export function SignOutForm() { return ( <form action={signOut}> <button type="submit">Sign out</button> </form> );}import { useAuth0 } from "@auth0/auth0-react";import * as vektis from "@vektis-io/tracker";
export function SignOutButton() { const { logout } = useAuth0();
const handleSignOut = async () => { await vektis.flush(); vektis.reset(); logout({ logoutParams: { returnTo: window.location.origin } }); };
return <button onClick={handleSignOut}>Sign out</button>;}Use the signOut event from next-auth/react:
"use client";
import { signOut } from "next-auth/react";import * as vektis from "@vektis-io/tracker";
export function SignOutButton() { const handleSignOut = async () => { await vektis.flush(); vektis.reset(); await signOut({ callbackUrl: "/" }); };
return <button onClick={handleSignOut}>Sign out</button>;}Hook into the onAuthStateChange event for SIGNED_OUT:
import { createClient } from "@supabase/supabase-js";import * as vektis from "@vektis-io/tracker";
const supabase = createClient(/* ... */);
supabase.auth.onAuthStateChange(async (event) => { if (event === "SIGNED_OUT") { await vektis.flush(); vektis.reset(); }});Hook into onAuthStateChanged:
import { getAuth, onAuthStateChanged } from "firebase/auth";import * as vektis from "@vektis-io/tracker";
const auth = getAuth();
onAuthStateChanged(auth, async (user) => { if (user === null) { await vektis.flush(); vektis.reset(); }});Wherever your sign-out handler lives, call flush() then reset() before clearing the session cookie:
import * as vektis from "@vektis-io/tracker";
export async function signOut() { await vektis.flush(); vektis.reset(); await fetch("/auth/sign-out", { method: "POST" }); window.location.href = "/";}After reset
Section titled “After reset”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.