data-debuglogs every event in the browser console and sends nothing. It works on localhost and in automated browsers, so a CI test can assert on it. Start here.data-allow-localhostsends real events from a local build, to check the whole path into the dashboard.
What the script ignores
The script loads and installswindow.crispstats but sends nothing when:
On the collector, headless browsers and HTTP clients such as
curl are also dropped by bot filtering.
Debug mode
Adddata-debug to the tag in development. Settings, Tracking code, Test before you ship has this tag with your key filled in:
localhost is in data-domains so the same tag works on your machine and on your domain. Open the page and the console shows one line per event, with the payload as a second argument:
localhost, automated browser, domain not allowed, do not track, opted out, excluded path, no pageview yet (under data-manual, before the first pageview()), or debug mode when nothing else applies. The full list is in script attributes.
In debug mode crispstats.id() resolves to undefined, and nothing at all leaves the page, so remove data-debug before you ship: a production page with it counts nothing. In a framework, read the flag from an environment variable so a production build can never carry it:
app/layout.tsx
Test tracking in CI
Automated browsers never send events, so a test cannot check the dashboard. It can check the console instead: withdata-debug on, every event the page would send is logged, in automated browsers too.
tests/analytics.spec.ts
NEXT_PUBLIC_CRISPSTATS_DEBUG=1. The same works in Puppeteer (page.on("console")) and Cypress (stub console.log on the window with cy.stub).
Send real events from a local build
To see local visits arrive in the dashboard, the script has to send them and the collector has to accept them.1
Allow localhost for a site
The collector only counts events from hostnames a site allows. Either:
- add a separate test site in the dashboard with
localhostas its Domain, which keeps test traffic out of your real reports (it counts toward your plan’s site limit), or - add
localhostunder Additional hostnames in Settings, General of your real site. Once a site has any additional hostname, its subdomains count only when listed, so add*.example.comtoo if you rely on subdomains. See exclude other hostnames.
2
Add data-allow-localhost to the tag
Settings, Tracking code, Test before you ship has this tag too:Remove
data-allow-localhost before you ship, or set it from an environment variable as above.3
Open the page over http
Serve the page from a local dev server, such as
http://localhost:5173. The collector only accepts http and https page URLs, so events from file:// pages are dropped. Use a normal browser window: automated browsers never send.Test a staging or preview deployment
Staging hosts are not local, so the script runs there, as long as the hostname is indata-domains and the collector accepts it:
- A subdomain of your site’s domain, such as
staging.example.com, passesdata-domains="example.com"and is counted while the site has no Additional hostnames. - Any other host, such as
my-app-git-main.vercel.appormy-app.workers.dev, is stopped bydata-domainson purpose, so previews do not count. To test one, give it its own test site and tag, or usedata-debug.
Confirm events are sent
With the normal tag on a live page:1
Open the network panel
Open the browser’s developer tools, select Network and type
/e in the filter. Reload the page.2
Check the request
You should see a
POST to https://in.crispstats.com/e (or to <data-api>/e behind a proxy) for the pageview, which some browsers list with the type ping. The body is JSON with your key in k, the event type in t and the page URL in u. The collector answers 202 with an empty body.A 202 does not mean the event was stored: the collector gives the same answer to an unknown key, a bot or a hostname the site does not allow. The setup check tells you more: open https://in.crispstats.com/check?k=cs_pk_xxxxxxxx (or <your proxy path>/check?k=…) and look for "site": "known" and your hostname in hostnames.3
Trigger an event
Call a custom event from the console:Another request to
/e appears, with "t":"event" and "n":"test event".Confirm events arrive
Open Realtime in the dashboard for the site you are testing. Pageviews and events appear in the Live feed within a few seconds. For a new site, the status row in Settings, Tracking code also shows Receiving events. once the first event is stored. If the network panel shows the request but nothing reaches Realtime, the collector dropped the event. See troubleshooting.Next steps
Troubleshooting
A checklist for when nothing shows up.
Script attributes
data-debug, data-domains and every other option.
Exclude traffic
Keep staging copies and your own visits out of production numbers.