> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Test tracking on localhost, in CI and on staging

> Why CrispStats ignores localhost and automated browsers, how data-debug shows every event in the console, how to assert on it in Playwright, and how to send real events from a local build.

CrispStats ignores local pages and automated browsers on purpose, so development visits and test runs never reach your numbers. That also means a local test shows nothing in the dashboard. To test, use one of two tags in development, never in production:

* **`data-debug`** logs 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-localhost`** sends real events from a local build, to check the whole path into the dashboard.

## What the script ignores

The script loads and installs `window.crispstats` but sends nothing when:

| Situation | Why | Turn it off with |
| - | - | - |
| The hostname is `localhost`, `*.localhost`, `127.x.x.x` or `[::1]`, or the page is a `file://` URL | Development visits would pollute your numbers. | `data-allow-localhost`, or `data-debug` to see the events without sending them |
| `navigator.webdriver` is set (Playwright, Puppeteer, Selenium), or the page runs in Cypress | Automated browsers are not visitors. | Nothing sends from them. `data-debug` logs their events. |
| The hostname is not in `data-domains` | Copies of your site elsewhere should not count. | Add the hostname to `data-domains`. |
| `localStorage.crispstats_ignore` is `1` | The [owner opt-out](https://docs.crispstats.com/tracking/exclude-traffic.md#exclude-your-own-browser) is on in this browser. | `localStorage.removeItem("crispstats_ignore")` |

On the collector, headless browsers and HTTP clients such as `curl` are also dropped by [bot filtering](https://docs.crispstats.com/privacy/bot-filtering.md).

## Debug mode

Add `data-debug` to the tag in development. **Settings**, **Tracking code**, **Test before you ship** has this tag with your key filled in:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script
  defer
  data-site="cs_pk_xxxxxxxx"
  data-domains="example.com,localhost"
  data-debug
  src="https://in.crispstats.com/d.js"
></script>
```

`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:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
crispstats: pageview not sent (localhost) {k: "cs_pk_xxxxxxxx", t: "pageview", u: "http://localhost:3000/", ...}
crispstats: event not sent (localhost) {k: "cs_pk_xxxxxxxx", t: "event", n: "signup", p: {plan: "pro"}, ...}
```

The word in brackets says why the event would not have been sent without debug mode: `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](https://docs.crispstats.com/tracking/script-attributes.md#when-the-script-sends-nothing).

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:

```tsx app/layout.tsx theme={"theme":{"light":"github-light","dark":"github-dark"}}
<Script
  src="https://in.crispstats.com/d.js"
  data-site="cs_pk_xxxxxxxx"
  data-domains="example.com,localhost"
  {...(process.env.NEXT_PUBLIC_CRISPSTATS_DEBUG === "1" ? { "data-debug": "" } : {})}
  strategy="afterInteractive"
/>
```

## Test tracking in CI

Automated browsers never send events, so a test cannot check the dashboard. It can check the console instead: with `data-debug` on, every event the page would send is logged, in automated browsers too.

```ts tests/analytics.spec.ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { expect, test } from "@playwright/test";

test("counts the page and the signup", async ({ page }) => {
  const events: { t: string; n?: string; u: string }[] = [];
  page.on("console", async (message) => {
    if (!message.text().startsWith("crispstats: ")) return;
    events.push(await message.args()[1]!.jsonValue());
  });

  await page.goto("/");
  await page.getByRole("button", { name: "Create account" }).click();

  await expect.poll(() => events.map((event) => event.t)).toContain("pageview");
  await expect.poll(() => events.some((event) => event.t === "event" && event.n === "signup")).toBe(true);
});
```

Run your app with the debug flag for the tests, for example `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 `localhost` as its **Domain**, which keeps test traffic out of your real reports (it counts toward your plan's site limit), or
* add `localhost` under **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.com` too if you rely on subdomains. See [exclude other hostnames](https://docs.crispstats.com/tracking/exclude-traffic.md#exclude-other-hostnames).

**2. Add data-allow-localhost to the tag**

**Settings**, **Tracking code**, **Test before you ship** has this tag too:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script
  defer
  data-site="cs_pk_xxxxxxxx"
  data-domains="example.com,localhost"
  data-allow-localhost
  src="https://in.crispstats.com/d.js"
></script>
```

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 in `data-domains` and the collector accepts it:

* A subdomain of your site's domain, such as `staging.example.com`, passes `data-domains="example.com"` and is counted while the site has no **Additional hostnames**.
* Any other host, such as `my-app-git-main.vercel.app` or `my-app.workers.dev`, is stopped by `data-domains` on purpose, so previews do not count. To test one, give it its own test site and tag, or use `data-debug`.

To keep staging out of your production numbers, give staging its own site and key. See [exclude traffic](https://docs.crispstats.com/tracking/exclude-traffic.md).

## 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](https://docs.crispstats.com/tracking/proxy.md)) 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:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
crispstats("test event", { source: "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](https://docs.crispstats.com/help/troubleshooting.md#events-arrive-but-the-dashboard-stays-empty).

## Next steps

> [card] [Troubleshooting](https://docs.crispstats.com/help/troubleshooting.md)
>
> A checklist for when nothing shows up.

> [card] [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md)
>
> data-debug, data-domains and every other option.

> [card] [Exclude traffic](https://docs.crispstats.com/tracking/exclude-traffic.md)
>
> Keep staging copies and your own visits out of production numbers.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.