init() inside onMount in your root layout so it only runs in the browser:
onMount only runs on the client, so init() is never called during SSR. No extra guard needed.Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Install Tracelit in a Svelte or SvelteKit project using onMount in the root layout. SSR-safe and automatic route tracking included.
npm install @tracelit/tracker
init() inside onMount in your root layout so it only runs in the browser:
<!-- src/routes/+layout.svelte -->
<script>
import { onMount } from 'svelte'
import { init } from '@tracelit/tracker'
onMount(() => init({ token: 'YOUR_TOKEN_HERE', environment: 'production' }))
</script>
<slot />
environment. Only "production" and "development" are accepted. If omitted, events default to development.onMount only runs on the client, so init() is never called during SSR. No extra guard needed.<!-- src/routes/+layout.svelte -->
<script>
import { onMount } from 'svelte'
import { init, identify, reset } from '@tracelit/tracker'
export let data // from +layout.server.ts
onMount(() => {
init({ token: 'YOUR_TOKEN_HERE', environment: 'production' })
if (data.user) {
identify(data.user.id, { email: data.user.email, plan: data.user.plan })
}
})
// React to auth changes
$: if (data.user) identify(data.user.id, { email: data.user.email })
$: if (!data.user) reset()
</script>
<slot />
Install Tracelit in my SvelteKit project.
Initialize @tracelit/tracker in src/routes/+layout.svelte inside onMount:
init({ token: 'YOUR_TOKEN_HERE', environment: 'production' })
Make minimal edits, show changed files, and include a 30-second verification checklist.