Skip to main content
Use the browser entry for a Svelte application. In SvelteKit, mount one component from the root layout to initialize Bily in the browser. Do not add a raw Bily script tag alongside the SDK.

Install Bily

Add Bily to Svelte

For a Svelte application built with Vite, store the complete tracking URL in a public build variable.
.env
Start Bily from one browser module.
src/bily.ts
Import the module once before your existing application mount.
src/main.ts
The browser script records the initial page and supported client-side navigation automatically. Do not add manual PageView calls for those navigations; use track() for business events.

Add Bily to SvelteKit

Use a public static environment value when the URL belongs in the browser bundle.
.env
Create one component. onMount() starts Bily only in the browser.
src/lib/BilyTracking.svelte
Mount it once from the root layout. Keep the layout’s existing data, snippets, providers, and application shell.
src/routes/+layout.svelte
If your project uses legacy slot syntax, keep its existing <slot /> and add only <BilyTracking /> beside it. The browser script records the initial page and supported client-side navigation automatically. Do not add manual PageView calls for those navigations; use track() for business events.

Track successful actions

src/lib/SubscribeButton.svelte
Use your project’s current event syntax. The Bily call stays the same.

Replace a bundled URL

Both VITE_ and $env/static/public values are included in built browser assets. Rebuild and redeploy after Bily validates a customer subdomain and gives you a new complete URL.

Verify Svelte tracking

Confirm one initial page, one event per later URL, and no duplicate script.

Replace the tracking URL

Change the complete public value through one controlled deployment.