Skip to content

SvelteKit

This guide covers SvelteKit. Tested with @sveltejs/kit@2.

Terminal window
npm install @vektis-io/tracker

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

Terminal window
PUBLIC_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.

The tracker is browser-only. Initialize it inside a top-level +layout.svelte so it runs on every page once the bundle hydrates:

src/routes/+layout.svelte
<script lang="ts">
import { onMount } from "svelte";
import { PUBLIC_VEKTIS_KEY } from "$env/static/public";
import * as vektis from "@vektis-io/tracker";
onMount(() => {
vektis.init({ apiKey: PUBLIC_VEKTIS_KEY });
});
</script>
<slot />
import * as vektis from "@vektis-io/tracker";
vektis.identify({
customer_id: "acct_A1",
user_id: "user_123",
});

Call this from whatever store or load function exposes the authenticated user — typically a Svelte store subscription that fires once the session is hydrated.

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" }