Add privacy-first analytics to your SvelteKit app
Set up Measure in SvelteKit — no cookies, a couple of KB, works with SvelteKit routing and SSR out of the box.
SvelteKit apps are built to be fast. Then developers add a typical cookie-based analytics tool and ship a heavy tracking bundle that sets cookies, comes with a consent banner, and defeats the purpose of choosing Svelte in the first place.
Measure is a couple of KB, uses no cookies, stores nothing on the visitor’s device so no cookie banner is needed for it, and has an MCP server so your AI tools can query your traffic data directly. Here’s how to set it up in SvelteKit.
Basic setup
Add the tracking script to your app.html (SvelteKit’s HTML template):
<!-- src/app.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
%sveltekit.head%
<script defer src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script>
</head>
<body>
%sveltekit.body%
</body>
</html>That’s it — for static sites built with adapter-static and for full SvelteKit apps alike.
SvelteKit navigation tracking
SvelteKit uses client-side routing after the initial page load. You don’t need an afterNavigate hook to track it: the Measure script hooks the browser’s history API, so every client-side navigation (pushState) and back/forward navigation (popstate) is recorded as a pageview. It records time on page as well.
Tracking conversions
The script is pageviews only — there’s no JavaScript API for custom events. To count signups, purchases and the like:
- Use a destination page.
goto('/welcome')or redirect to/thanksafter the action; that path’s pageviews are your conversion count. - Send it from the server. In a form action or
+server.jsendpoint, post to the REST API. Keep themk_API key server-side:
// src/lib/server/measure.js
import { MEASURE_API_KEY, MEASURE_TRACKING_ID } from '$env/static/private'
export async function recordMeasureEvent(path) {
await fetch('https://lets.measure.events/api/v1/events', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${MEASURE_API_KEY}`
},
body: JSON.stringify({ site_key: MEASURE_TRACKING_ID, path })
})
}
// in a form action: await recordMeasureEvent('/events/signup')Server-side rendering
The tracking script in app.html only executes client-side (the defer attribute ensures this). No special SSR handling is needed. Measure doesn’t set cookies, so there’s no server-side cookie management to worry about either.
If you’re using SvelteKit’s +page.server.js load functions, pageview tracking happens purely on the client — your server functions don’t need to know about it.
Why Svelte developers switch from heavyweight analytics
Performance alignment. You chose Svelte because it compiles to minimal JavaScript. A typical analytics bundle adds tens of KB of runtime JavaScript that can’t be compiled away. Measure adds a couple of KB, externally loaded.
No cookie banner. Measure doesn’t use cookies, stores nothing on the visitor’s device, and doesn’t store IP addresses or user-agent strings — visitors are counted with a daily-rotating salted hash. So there’s no cookie banner needed for Measure cluttering your carefully designed Svelte UI.
Humans, agents and bots, separately. Measure counts human visitors, AI agents (ChatGPT-User, ClaudeBot, PerplexityBot and friends) and other bots separately, so your numbers aren’t inflated by crawlers.
MCP server. Ask your AI coding tools “what pages are getting traffic?” and get answers from your real data. For Svelte developers using Cursor or Claude, this is a workflow integration, not just a dashboard.
Adapter compatibility
Measure works with all SvelteKit adapters:
- adapter-auto — works out of the box
- adapter-static — perfect fit; script loads on every static page
- adapter-node — works; script is client-side only
- adapter-vercel / adapter-netlify — works; no server-side dependencies
Getting started
- Sign up at lets.measure.events — $29/month covers 40 sites, with a 14-day trial
- Add the script tag to
src/app.html - Optional: send server-side events from form actions
- Optional: connect the MCP server (
https://lets.measure.events/mcp) for AI-powered analytics queries
Setup time: 3 minutes. Bundle impact: zero (external script with defer).
Let your agent read the numbers.
$29 a month covers 40 sites, then $0.50 a site. 14-day trial.