Create React App
This guide covers Create React App (CRA) projects.
1. Install the package
Section titled “1. Install the package”npm install @vektis-io/trackerpnpm add @vektis-io/trackeryarn add @vektis-io/tracker2. Add your API key
Section titled “2. Add your API key”Generate a key at Settings → API Keys in the VEKTIS dashboard, then create or update .env.local:
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.
3. Initialize the SDK
Section titled “3. Initialize the SDK”Initialize once in src/index.tsx, before your app renders:
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>,);4. Identify the user after sign-in
Section titled “4. Identify the user after sign-in”import * as vektis from "@vektis-io/tracker";
vektis.identify({ customer_id: "acct_A1", user_id: "user_123",});5. Send an event
Section titled “5. Send an event”vektis.track("feature.used", { feature_id: "reports-dashboard" });6. Verify the install
Section titled “6. Verify the install”In the browser dev console:
vektis.getStatus();// { state: "READY", queueLength: 0, identityCustomerId: "acct_A1", identityUserId: "user_123" }