Svelte
Initialize Tracwell in the browser entry before mounting the Svelte application.
Initialize Tracwell
src/main.ts
import { mount } from "svelte";
import { createTracwell } from "tracwell";
import App from "./App.svelte";
export const analytics = createTracwell({
collectionMode: "product",
projectKey: "tw_live_...",
});
mount(App, {
target: document.getElementById("app")!,
});Import analytics where you track custom events. A normal Svelte SPA router is covered when it updates browser history.
Track an event
Keep the initialized client available to the components or services that own successful product outcomes, then call track() after the outcome completes.
TypeScript
const eventId = analytics.track("signup_completed", {
plan: "starter",
source: "pricing",
});
if (!eventId) {
// Collection is blocked or the event did not pass validation.
}Continue with the custom events guide for naming, property limits, and verification.