> ## 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.

# Track 404 pages

> Record visits to not-found pages as one 404 event per view with the path, using data-404 with a meta tag, a CSS selector or the page's HTTP status, so you can fix broken links.

To see which missing pages people land on, add `data-404` to the CrispStats script tag and mark your not-found page with `<meta name="crispstats:404">`. Each view of a marked page sends one `404` event with the page's `path` property, so the **Events** screen lists the broken paths and how often they are hit. The pageview itself is still counted as usual.

## Set it up

**1. Turn on the module**

Add `data-404` to your script tag (`data-404=""` in JSX), or turn on **404 pages** in **Settings**, **Tracking code** and copy the updated snippet:

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

Use `d.js`, the default script. The smaller `d.core.js` build leaves this module out and ignores the attribute.

**2. Mark your not-found page**

Add this tag to your 404 page, and only that page:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<meta name="crispstats:404" />
```

The tag needs no `content`: the script only checks that a `meta` element with this name is in the document. It can be in `<head>` or in `<body>`. For Next.js, see [404 pages in Next.js](https://docs.crispstats.com/install/nextjs.md#track-404-pages).

**3. Visit a missing URL**

Open a path that does not exist on your live site, then open **Events** in the dashboard. Select the `404` event and its `path` property to see which paths were requested.

## How a page is recognised

A page counts as not found when any of these is true:

| Signal | Where it works |
| - | - |
| A `<meta name="crispstats:404">` element is in the document | Everywhere, full page loads and single-page navigation. |
| An element matches the selector in `data-404` | Everywhere. See [use a selector](#use-a-selector-instead-of-a-meta-tag). |
| The server answered the page with HTTP status `404` | Full page loads in Chromium-based browsers (Chrome, Edge), which expose the status as `responseStatus` on the page's navigation entry. Only while the URL is still the one the server sent. |

The status is a bonus, not a replacement for the marker: other browsers do not expose it, and a single-page navigation has no HTTP status. Keep the meta tag or selector.

## When the check runs

The script checks after every pageview, and gives a page that renders its not-found view late a few chances:

| Pageview | Checks |
| - | - |
| The page the server sent | At once, after 1 second and after 3 seconds. |
| A single-page navigation | After 1 second and after 3 seconds. Never at once: at that moment the page may still show the view you are leaving, so a 404 page that links to `/pricing` would otherwise report `/pricing` as missing. |

It reports at most once per pageview: the first check that finds the page not found sends the event and stops the others. A new pageview cancels the checks still pending for the previous one. So:

* one view of a missing page sends exactly one `404` event, however many checks run,
* a slow page that shows its not-found view within 3 seconds is still counted,
* visiting the same missing URL again, in the same page load or later, counts again.

Nothing is sent on a page excluded with `data-exclude` or on a page the script is not tracking.

## Use a selector instead of a meta tag

If adding a `<meta>` tag is awkward, for example in a single-page app that renders the not-found view in the body, give `data-404` a CSS selector for an element that only that view contains:

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

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<main data-not-found>
  <h1>Page not found</h1>
  <p>The page you are looking for does not exist.</p>
</main>
```

The meta tag still works when you set a selector: the page counts as not found if either is present. Use a selector the browser can parse. With a selector it cannot parse, only the HTTP status is used.

## What is sent

| Field | Value |
| - | - |
| Event name | `404` |
| Property `path` | `location.pathname` of the page: the path without the query string or fragment. |

A `404` event is a custom event, so it counts toward your plan's monthly events like any other. See [plans and limits](https://docs.crispstats.com/account/plans-and-limits.md#what-counts-as-an-event).

## Next steps

> [card] [Outbound links and downloads](https://docs.crispstats.com/track/outbound-links-and-downloads.md)
>
> Turn on the other click-tracking modules.

> [card] [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md)
>
> Every attribute the script tag accepts.

> [card] [Events in the dashboard](https://docs.crispstats.com/dashboard/events.md)
>
> Filter and break down the `404` event by path.


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