How to add analytics to your SvelteKit site
This adds measuremy.site, cookieless website analytics, to a SvelteKit site. It is one script tag of under 1 KB: no cookies, no npm package, no consent banner for the tracker. The free plan covers 5,000 pageviews a month.
The quickest way: ask your coding agent
Add measuremy.site analytics to this project: connect the measuremy.site MCP server at https://a.measuremy.site/mcp (it signs in with OAuth, no key), then tell me how to sign in. Details: measuremy.site/llms.txtThe agent connects to measuremy.site, you sign in through your browser, and it adds the tag below to the right file for you. To do it by hand, follow the steps.
1. Get your site key
Create a free account and add your domain. The Setup tab shows your snippet with your site key filled in. The key is public and can only record visits, so it is safe in your source code.
2. Add the script tag
Add the tag to src/app.html, inside <head> and before %sveltekit.head%:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script defer src="https://a.measuremy.site/t.js" data-key="YOUR_SITE_KEY"></script>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
SvelteKit's client-side navigation uses the History API, so each page change is counted once. Preloading on hover doesn't count as a visit.
3. Check it works
Publish the change, then open your live site. The first visit from your own domain verifies it and the visit shows up on the dashboard within seconds. Visits from localhost aren't counted, so test on the deployed site.
4. Track signups and other conversions
From a component, after the action completes:
<script lang="ts">
async function signup() {
await createAccount();
window.measuremysite?.track("signup");
}
</script>
Or, with no JavaScript, add data-measuremysite-event="signup_click" to any link, button or form.
Any event counts as a conversion for the channel the visitor came from.
Other platforms, and funnels and campaign links, are in the install guide.
Try it on your site
Free for 5,000 pageviews a month, no card. Paste one sentence into your coding agent, or add one script tag yourself.
Start free See the live demoAdd measuremy.site analytics to this project: connect the measuremy.site MCP server at https://a.measuremy.site/mcp (it signs in with OAuth, no key), then tell me how to sign in. Details: measuremy.site/llms.txt
More guides
- A website analytics MCP server: ask your agent about your traffic
- Add website analytics to your project with Claude Code
- Find out why your website traffic spiked
- Track clicks and find where visitors drop off, without writing code
- Cookieless analytics: how it works, and what you give up
- A simpler Google Analytics alternative for developers
- How to add analytics to your Next.js site
- How to add analytics to your Astro site
- How to add analytics to your Vite, React or Vue site
- How to add analytics to your Hugo site
- How to add analytics to your WordPress site