Skip to content

Create React App

This guide covers Create React App (CRA) projects.

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
REACT_APP_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/index.tsx, before your app renders:

src/index.tsx
import React from "react";
import ReactDOM from "react-dom/client";
import * as vektis from "@vektis-io/tracker";
import App from "./App";
vektis.init({ apiKey: process.env.REACT_APP_VEKTIS_KEY! });
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
import * as vektis from "@vektis-io/tracker";
vektis.identify({
customer_id: "acct_A1",
user_id: "user_123",
});
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" }