Skip to content

Vite + React

This guide covers Vite-based React apps. The same approach works for Vite + Vue or Vite + Svelte if you initialize the SDK in your equivalent root entry file.

Terminal window
npm install @vektis-io/tracker

Generate a key at Settings → API Keys in the VEKTIS dashboard, then create or update .env.local:

Terminal window
VITE_VEKTIS_KEY=vk_pub_prd_...

Use a publishable key (vk_pub_*) — it’s scoped to event ingest only and safe to ship in your browser bundle.

Initialize once in src/main.tsx (or src/main.ts for non-React Vite apps), before your app renders:

src/main.tsx
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import * as vektis from "@vektis-io/tracker";
import App from "./App";
import "./index.css";
vektis.init({ apiKey: import.meta.env.VITE_VEKTIS_KEY });
createRoot(document.getElementById("root")!).render(
<StrictMode>
<App />
</StrictMode>,
);
import * as vektis from "@vektis-io/tracker";
vektis.identify({
customer_id: "acct_A1",
user_id: "user_123",
});

Call this from wherever your app learns who the user is — a session-loaded hook, an auth provider callback, or directly after a successful login response.

import * as vektis from "@vektis-io/tracker";
vektis.track("feature.used", { feature_id: "reports-dashboard" });

In the browser dev console:

vektis.getStatus();
// { state: "READY", queueLength: 0, identityCustomerId: "acct_A1", identityUserId: "user_123" }