---
url: https://simpledatalogs.com/docs/quickstarts/sveltekit.md
description: >-
  Add simpledatalogs to a SvelteKit app in one minute, with page views, sessions
  and errors captured by one line.
---

# SvelteKit

## Install

```sh
npx simpledatalogs init
npm install simpledatalogs
```

## Or by hand

```sh
# .env
PUBLIC_SIMPLEDATALOGS_KEY=sdl_pub_…
```

```js
// src/hooks.client.js
import { init } from 'simpledatalogs'
import { PUBLIC_SIMPLEDATALOGS_KEY } from '$env/static/public'

init({ key: PUBLIC_SIMPLEDATALOGS_KEY, autocapture: true })
```

`hooks.client` runs once in the browser, so the client is created once.

## Only your own events

```js
// src/lib/analytics.js
import { init } from 'simpledatalogs'
import { PUBLIC_SIMPLEDATALOGS_KEY } from '$env/static/public'

export const sdl = init({ key: PUBLIC_SIMPLEDATALOGS_KEY })
```

Import `sdl` only from browser code (components, `+page.svelte`), not from server load functions.

## In the first minute

* `session_start` and a `page_view` with `path`, `title`, `referrer` and `utm_*`.
* A `page_view` on every client-side navigation.
* Uncaught errors and unhandled rejections on the **Logs** tab.

## Autocapture defaults

| Feature | `autocapture: true` |
|---|---|
| Page views, including client navigation | on |
| Sessions | on |
| Errors and unhandled rejections | on |
| Outbound link clicks | off |
| Do Not Track / Global Privacy Control | respected |
