Skip to main content
The CrispStats script reads all of its options from data- attributes on its own <script> tag. Only data-site is required: with it you get pageviews, single-page navigation and engagement. The dashboard also adds data-domains with your site’s domain, so copies of your site elsewhere are not counted. Every other attribute is off until you add it.
Use a classic script tag with defer or async. type="module" does not work, because the script finds its options through document.currentScript, which is not set for modules. Do not give the tag id="crispstats": browsers expose an element’s id as a global, so window.crispstats would be the element until the script loads.

Write flag attributes

A flag attribute is on as soon as it is present, whatever its value. Write it the way your platform expects: Settings, Tracking code writes every option this way for each platform tab. An option starts working once the updated snippet is on your site.

Where it runs

string
required
The site’s public key, which starts with cs_pk_. It tells the collector which site an event belongs to and is safe to publish. Without it the script tracks nothing.
string
default:"any hostname"
Only track on these hostnames and their subdomains, separated by commas: data-domains="example.com,shop.example.org". Preview deployments, workers.dev copies, staging hosts and scraped copies of your pages then send nothing. The dashboard fills it in with the site’s Domain and Additional hostnames. A leading www. is not special: example.com covers www.example.com because it is a subdomain.
string
default:"the origin the script was loaded from"
Base URL of the collector, without a trailing slash. Events go to <api>/e and crispstats.id() asks <api>/id. With the standard tag this is https://in.crispstats.com. A path works too, for a first-party proxy: data-api="/k3x9qe" sends events to /k3x9qe/e on your own domain. See proxy.
string
default:"none"
Paths not to track, separated by commas or spaces: data-exclude="/admin, /admin/*, /preview". See exclude paths for the exact matching rule. Nothing is sent from an excluded page: no pageview, no engagement and no custom events. Its URL is never used as a referrer.
flag
default:"off"
Send events from localhost, 127.x.x.x, [::1], *.localhost and file:// pages, which are ignored otherwise. The collector still drops them unless localhost is one of the site’s hostnames. Remove it before you ship. See localhost and testing.
flag
default:"off"
Log every event in the browser console and send nothing. It also logs on localhost, in automated browsers and on hostnames outside data-domains, and each line says why the event would not have been sent there. Use it to test locally and in CI; never ship it, because a page with data-debug sends nothing. See debug mode.
flag
default:"off"
Do not track browsers that send the Do Not Track signal. The script collects no personal data either way, so this is off by default.

What is sent

string
default:"none"
Query parameters to keep on the page URL and the referrer, on top of the defaults, separated by commas: data-keep-params="page,lang". data-keep-params="*" keeps the whole query string, as the script did before it cut query strings. Names match without regard to case. See what the script sends.
flag
default:"off"
Treat the URL fragment as part of the page, for hash routers whose URLs look like /#/settings. Only a fragment that starts with #/ or #!/ is sent; in-page #anchors and tokens such as #access_token= never are. Sites with real paths, such as Next.js, Nuxt, SvelteKit, Astro and Remix, do not need it. See single-page apps.
flag
default:"off"
No automatic pageviews. The script counts a pageview only when your code calls crispstats.pageview(), including on the first page load. Use it only for a router the script cannot see. Custom events sent before the first pageview() call are dropped. See single-page apps.
flag
default:"off"
Keep a random visitor id in localStorage.crispstats_vid, so returning visitors are recognised across days. Do not add it by hand: turn on Persistent visitors in Settings, General, and the snippet in Settings, Tracking code includes it. See persistent visitors.

Optional modules

Each module is off until its attribute is on the tag. They are in d.js and left out of the smaller d.core.js, which ignores these attributes. See script builds.
flag
default:"off"
Sends an Outbound link event with a url prop for clicks and middle clicks on http and https links to another host. See outbound links and downloads.
flag or string
default:"off"
Sends a File download event with a url prop for links with a download attribute or a known file extension: pdf, xlsx, docx, txt, rtf, csv, exe, key, pps, ppt, pptx, 7z, pkg, rar, gz, zip, avi, mov, mp4, mpeg, wmv, midi, mp3, wav, wma and dmg. Give a list to replace the defaults: data-downloads="pdf, epub".
flag
default:"off"
Sends one vitals event the first time the page is hidden, with LCP, INP, CLS, FCP and TTFB as far as the browser supports them. See web vitals.
flag
default:"off"
Reports uncaught errors and unhandled promise rejections, each distinct error once and at most ten per page load. Cross-origin Script error. messages and failed resource loads are skipped. See JavaScript errors.
flag or string
default:"off"
Sends one 404 event with a path prop per pageview of a page that was not found: a page with <meta name="crispstats:404">, an element that matches the selector you give (data-404=".not-found"), or, in Chromium browsers, a full page load that the server answered with 404. See 404 pages.
The Outbound link and File download events carry the link’s URL in url, and a JavaScript error carries its script’s URL in source. These are cut the same way as the page URL, and lose their fragment.

What the script sends

Every event carries the page URL and the referrer. Before either leaves the browser, the script cuts them:
  • The fragment (#…) is removed. Fragments often carry tokens such as #access_token=. With data-hash on, a fragment that is a route (#/… or #!/…) is kept; any other fragment, such as #pricing or #access_token=, is still removed.
  • The query string is cut to the parameters analytics needs. Query strings carry license keys, password reset tokens, checkout session ids and e-mail addresses, so everything else is removed.
  • The length is capped at 2,048 characters.
The parameters that stay: So /activate?key=LIC-123&utm_source=newsletter&gclid=Cj0KCQ is sent as /activate?utm_source=newsletter&gclid=1. The order of the parameters is kept. The collector then stores even less: the path, the query parameters listed under Query parameters in Settings, General, UTM values in their own fields, and only the host of the referrer. See data collected. When you keep a parameter in Settings, General, the snippet in Settings, Tracking code adds it to data-keep-params for you, so the browser does not cut what you asked the collector to keep.

Exclude paths

data-exclude takes a list of patterns, each matched against the whole path of the page (without the query string):
  • * matches any characters, slashes included.
  • A trailing slash on the page’s path is optional.
  • Everything else matches literally.
For an admin section and nothing else, use /admin, /admin/*. /admin* also matches every path that starts with /admin, such as /administrator. Excluded paths in Settings, General works on the collector instead, with a different rule: there * stays within one path segment and ** crosses segments. See exclude traffic.

Persistent visitors

Without persistent visitors, CrispStats recognises a visitor for one day, from a hash, and stores nothing in the browser. With it, the script keeps a random id in localStorage.crispstats_vid and the collector uses that id, so a visitor is recognised across days. It takes one switch in the dashboard, and the snippet follows it:
  1. Turn on Persistent visitors in Settings, General.
  2. Copy the snippet again from Settings, Tracking code. It now includes data-persist. Deploy it.
Both halves are needed, and the dashboard keeps them together: the collector ignores the id while the setting is off, and the script creates no id without data-persist. If you write the tag by hand, add data-persist only while the setting is on. It stores an identifier on the visitor’s device, which may need consent: read persistent visitors before you turn it on.

The crispstats global

The script installs window.crispstats. It exists even when the script decides not to track (on localhost, for an opted-out browser, outside data-domains), so calling it is always harmless.
For types in TypeScript, see TypeScript.

Declarative events

Any element with a data-cs-event attribute sends that event when it, or anything inside it, is clicked. Each data-cs-prop-* attribute becomes a prop. This works in both builds. See declarative events.

Call the global before the script loads

The script is deferred, so inline code can run before it exists. Put this stub above the script tag. Calls made before the script loads are queued, then replayed in order after the script has started:
The stub checks that window.crispstats is a function, not only that it exists, because an element with id="crispstats" would make it exist. It queues crispstats(), identify, revenue and pageview. It has no id() and no v: call crispstats.id() from code that runs after the page has loaded, such as a click handler. For a TypeScript module, use the stub on the TypeScript page. The script replaces the stub with the real function. If a copy of the script already ran on the page, a second copy sees crispstats.v and does nothing.

When the script sends nothing

The script loads, installs window.crispstats, and sends nothing at all when the first of these applies. With data-debug on, each console line names the one that applies: While a page is being prerendered, the script waits and counts the pageview when the page is shown.

Next steps

Single-page apps

How route changes are seen, and pageview() for routers that hide them.

Localhost and testing

Debug mode, local builds and tests in CI.

Script builds

Which file is which, and how it is cached.
Last modified on November 18, 2026