---
title: "Svelte"
description: "Initialize Tracwell in the browser entry before mounting the Svelte application."
documentation: "https://tracwell.app/docs/frameworks/svelte"
markdown: "https://tracwell.app/docs/frameworks/svelte.md"
---

# Svelte

> Initialize Tracwell in the browser entry before mounting the Svelte application.

## Initialize Tracwell

```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 component or service that owns the successful product outcome. Call `track()` only after that outcome completes.

```ts
const eventId = analytics.track("signup_completed", {
  plan: "starter",
  source: "pricing",
});

if (!eventId) {
  // Collection is blocked or the event did not pass validation.
}
```

See the [custom events guide](https://tracwell.app/docs/events.md) for naming, property limits, and verification.
