Script configuration
The one-line snippet works with no options. Everything below is optional — set it with a data-* attribute on the <script> tag. Installing from npm instead? The JavaScript SDK exposes every option here as a camel-cased initStatlark() field.
Using an AI coding tool?Hand it the prompt below, or point it at this page as markdown: script-configuration.md
Subdomain tracking
By default Statlark scopes the visitor cookie to your registrable domain (e.g. .example.com), so a visitor who lands on your marketing site and later signs up on app.example.com stays the same person and keeps their original attribution. It works out of the box — no configuration — and falls back to the current host if a domain can’t be resolved.
<!-- Default: the visitor cookie is scoped to your registrable domain, so a
visitor who moves from www.example.com to app.example.com stays one person. -->
<script defer src="https://statlark.com/script.js" data-website-id="sl_xxxx"></script>
<!-- Force an explicit cookie domain, or "none" to opt out (host-only). -->
<script defer src="…" data-website-id="sl_xxxx" data-cookie-domain=".example.com"></script>Set data-cookie-domain to pin an explicit domain, or to none to opt out and keep the cookie host-only. Once you track across subdomains, a Subdomains breakdown appears on the Locations card of your Overview.
All options
| Attribute | Values | Default | What it does |
|---|---|---|---|
data-website-id | sl_… | Required | Your site id, from Settings → Install. |
data-api | a URL or path | hosted collector | Send events to a custom endpoint — used for a first-party proxy. |
data-cookie-domain | a domain, or none | auto | Cookie scope. Auto uses your registrable domain; none keeps the cookie host-only. |
data-allow-localhost | true | off | Count visits from localhost, 127.0.0.1, [::1], 0.0.0.0 and hosts ending in .local or .test. |
data-honor-dnt | true | off | Respect the browser’s Do Not Track signal and skip those visitors entirely. |
data-outbound | false | on | Turn off automatic outbound-link tracking. |
data-titles | false | on | Don’t send page titles. |
data-disable-payments | true | off | Make statlark.payment() a no-op. |
data-debug | true | off | Log every tracked hit to the console. data-disable-console silences all output instead. |
data-cookieless | true | off | Set no cookies or device storage at all — see cookieless mode. |
Hand this to your AI
For AI tools: this is the prompt a customer pastes in to start this task. If you are already following it, don’t start again: use the rest of this page as the guide.
Paste this into Claude Code, Cursor or another AI coding tool, in your project, then say the change you want, such as counting visits from localhost while you test. It never needs your API key.
Change a Statlark tracker option in this project. I'll say which change I want after this prompt. If I haven't, ask me.
Follow this guide for the exact option names: https://statlark.com/docs/script-configuration.md
If that link doesn't open, try the same address without .md. If neither opens, stop and tell me. Don't write this from memory.
1. Find how the site loads Statlark: the script tag, consent.js, @statlark/web or a first-party proxy. If it loads it in more than one place, stop and tell me. If you can't find it in this code, stop and ask me how it's added. If it's added somewhere else, such as Google Tag Manager, tell me the exact attribute to set there instead. Don't install it as part of this.
2. For the script tag, set the option as a data- attribute on that tag. For @statlark/web, use the matching field on initStatlark() or StatlarkProvider, from https://statlark.com/docs/javascript-sdk.md. Some names differ there. If the option has no match, stop and tell me.
3. If the site loads consent.js and the option isn't in the consent guide's list of controller options, stop and tell me: https://statlark.com/docs/consent.md
4. If I ask for cookieless mode and the site uses a first-party proxy, stop and tell me, because the two can't be combined. If I ask to turn cookieless mode off, stop and check with me first: the tracker will set cookies again, and visitors in the EU or UK may need to consent first. Don't remove a consent banner or tell me I no longer need one: that's for me to check with my DPO, as the guide says.
5. Make only the change I asked for, on the existing tag or call, and don't add a second copy of the script. Finish by telling me what you changed and anything I still have to do, such as deploying it, or undoing a change that was only for testing.The leave signal
When a page is hidden, left, or replaced by a single-page-app navigation, the tracker sends one small hit carrying how long the page was visible, the deepest scroll so far and the page title (read once the page has settled; the collector masks anything that looks like an email address and keeps 300 characters). That’s where session length, time on page and scroll come from.
It’s never billed and uses no storage. It can’t create a visitor: a signal from a browser Statlark hasn’t seen yet is dropped, so a first-time visitor who leaves within a moment of arriving can lose that page’s time. Older pinned versions of the script don’t send it, so their sessions use the time from first to last hit.
Cookieless mode
Cookieless mode is analytics that stores nothing on the visitor’s device: no cookies, no localStorage, no sessionStorage. Set data-cookieless="true" and the hosted collector derives a visitor id server-side instead, by hashing the request with a random salt that rotates and is discarded daily. Statlark keeps no copy of the salt or the IP once the day rolls over, so it can’t re-link a visitor from one day to the next.
The reason that matters legally: the consent requirement in ePrivacy Directive Article 5(3) is triggered by storing information on, or gaining access to information already stored in, a user’s device — not by analytics as such. Store nothing and read nothing, and the trigger doesn’t apply, which is why this mode can run without a cookie-consent banner. It is not legal advice — confirm it fits your situation with your DPO before relying on it.
Want to keep full cookie-mode attribution in the EU/UK instead? Show a consent banner — it holds the analytics cookie until the visitor accepts, so returning-visitor paths and multi-day attribution survive for everyone who opts in.
A few trade-offs to know:
- No long-horizon attribution. Because the salt rotates daily, a visitor who returns on a later day counts as new — you keep same-day visitor and conversion counts, not multi-day returning-visitor paths.
- Sessions stop at UTC midnight. Sessions are worked out from each visitor’s hits, so multi-page visits count as one session as usual, but the visitor id changes at UTC midnight, so a visit across it counts as two. A page left open across UTC midnight also loses its visible time.
- Hosted collector only. The id is derived in Statlark’s edge collector, so cookieless mode needs the default install — it cannot be combined with a first-party proxy.
- Sign-out isn’t an identity boundary. With nothing stored on the device there is no id to clear, so
reset()starts a new session but the same browser keeps the same visitor id until the salt rotates at UTC midnight. On a shared device, two people who sign in one after the other count as one visitor for the rest of that day. Cookie mode is the option that separates them. - No self-exclusion.
?statlark_ignore=1stores a flag inlocalStorage, which cookieless mode can’t use — so the link is a no-op and your own visits to the live site are counted. Visits fromlocalhostare still skipped automatically, and path, hostname and country exclusion rules are unaffected (they run server-side).
The visitor ID
Statlark stores a first-party visitor id in the _slk_vid cookie. Read it with getVisitorId() — handy for tying a server-side goal or payment to the same visitor.
// The current visitor id (the _slk_vid cookie), or null when the tracker isn't
// running (Do Not Track / localhost / self-excluded). Use it to key a
// server-side goal or payment to the same visitor.
const id = window.statlark?.getVisitorId();Resetting on sign-out
On sign-out, call reset() so the next person on that browser starts as a fresh anonymous visitor rather than inheriting the previous user’s id and first-touch attribution. It takes effect immediately, with no page reload. Call it from wherever your app handles an auth state change, so every open tab resets — not just the one that signed out.
// On sign-out: forget the visitor + session so the next person on this
// browser starts fresh. ?. on the method too — an older cached tracker
// won't have reset() yet.
window.statlark?.reset?.();In cookieless mode this starts a new session only — there is no id on the device to clear, so the same browser keeps the same visitor id until UTC midnight.
Nothing showing up?
If a site has never recorded a single event — not “quiet this week”, but nothing, ever — it is almost always one of three things.
- The snippet isn’t on the page. Open your site, view source, and search for
script.js. If you added it withnext/script, Google Tag Manager or the npm package, it’s added in the browser, so look in the Network tab of your browser’s developer tools instead. If it isn’t there, it may be sitting in a draft template or behind a caching layer that hasn’t been purged. - The site ID doesn’t match. Compare the
data-website-idin your snippet against thesl_…ID shown for that site in Settings. Statlark files a hit under whichever ID the snippet names, so a mismatch means the data is landing on a different site. - The domain is tracked twice. If the same domain was added more than once, only the copy whose ID is in your snippet will ever receive data — the other stays at zero forever. Remove the unused one; see Your account and your data.
Also worth ruling out: an exclusion rule that happens to match all of your traffic, and the Do Not Track and localhost options, which skip hits by design.
Last reviewed