<head> in index.html at the project root. Vite serves that file as the entry of your app, so every page gets the tag, and route changes through the History API are counted with no router code.
This page is for a Svelte app without SvelteKit. For SvelteKit, see SvelteKit. You need your site’s public key, which starts with cs_pk_, from Settings, Tracking code. There is no npm package to install.
Add the script
1
Add the tag to index.html
index.html
type="module", but the CrispStats tag must be a classic script with defer: the script reads its options from its own tag.2
Build, deploy and open your app
npm run dev serves on localhost, which the script ignores. Run npm run build, deploy the dist/ folder, then open your live app in a normal browser window.Routers
The same URL twice in a row is one pageview. See single-page apps.
Check that it works
- In your browser’s developer tools, the Network tab shows
d.jsloading fromin.crispstats.comand aPOSTtohttps://in.crispstats.com/eon the first load and on each route change. The collector answers202. - In CrispStats, Settings, Tracking code shows Receiving events., and the visit appears in Realtime within seconds.
npm run dev, add data-debug and localhost in data-domains while you develop. See localhost and testing.
Send custom events
src/lib/UpgradeButton.svelte
?.) keeps the button working when an ad blocker stops the script. In TypeScript, save crispstats.d.ts from TypeScript in src/. For clicks without code, use declarative events.
FAQ
Can I import the script from main.ts instead?
Can I import the script from main.ts instead?
There is no npm package to import. The script reads its options from its own
<script> tag, so it needs a tag: you could create one from code as the Google Tag Manager snippet does, but the tag in index.html is simpler and loads earlier.Every route shows as / in the dashboard.
Every route shows as / in the dashboard.
Your router keeps routes after
#. Add data-hash to the tag and redeploy.Can I count visitors who use ad blockers?
Can I count visitors who use ad blockers?
Serve the script from your own domain with a forwarding rule on your host. See proxy by host.
Next steps
Single-page apps
How route changes and engagement are tracked.
Custom events
Track signups, clicks and other actions with properties.
SvelteKit
The guide for SvelteKit apps.
Vite details (
index.html at the project root as the entry, and the svelte and svelte-ts templates) checked against https://vite.dev/guide/ on 2026-11-23.