> ## 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 JavaScript errors from real visits

> Collect uncaught JavaScript errors and unhandled promise rejections with data-errors, then group, search, resolve and ignore them on the Errors screen.

CrispStats records the JavaScript errors your visitors run into. Add `data-errors` to the script tag, and every uncaught error and unhandled promise rejection is sent with its message, source file, line, column and stack. The **Errors** screen groups the same error from many visitors into one row you can resolve or ignore.

## Turn on error tracking

Add the `data-errors` attribute to your existing script tag:

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

In JSX, write `data-errors=""`. In **Settings**, **Tracking code**, the **JavaScript errors** switch adds it to the snippet for your platform.

To confirm it works, deploy the change, open your live site and run this in the browser console:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
setTimeout(() => { throw new Error("CrispStats error test"); });
```

Then open **Errors** under **Health** in the site's sidebar and reload it. The error shows up as a group with the message `CrispStats error test`. Resolve or ignore it when you are done.

> [!NOTE]
>
> An error thrown straight from the console prompt is not always reported as uncaught by the browser. Wrapping it in `setTimeout` makes it a normal uncaught error. If you excluded your own browser with `localStorage.crispstats_ignore`, the script sends nothing from it, so run the test in a private window.

## What is captured

The script listens for uncaught errors and unhandled promise rejections and sends one event of type `error` for each, with these fields:

| Field | Content |
| - | - |
| `message` | The error message, or for a rejection the reason's `message` (or the reason itself). Cut at 1,000 characters. |
| `source` | The URL of the script file the error came from. Cut at 500 characters. Not available for promise rejections. |
| `line`, `col` | Line and column in that file. Not available for promise rejections. |
| `stack` | The stack trace, when the browser provides one. Cut at 4,000 characters. |

Each event also carries what every CrispStats event carries: the page URL, referrer, screen width, browser language and timezone.

### Limits in the browser

* **Once per distinct error.** An error with the same message, source file and line is sent once per page load, however often it repeats.
* **Ten per page load.** After ten errors, the script sends no more until the next page load.
* **Cross-origin errors are skipped.** For a script loaded from another origin without CORS, the browser reveals only `Script error.` with no details. Those are not sent, because there is nothing to act on.
* **Failed resource loads are skipped.** An image or script that fails to load carries no message and is not reported.

> [!WARNING]
>
> Stack traces and error messages are sent as the browser reports them, and stacks can contain URLs from your own site. Keep personal data out of the error messages your code throws.

## How errors are grouped

CrispStats groups errors by their message (the first 500 characters) and source file. Every error with the same message from the same file is one group, whatever page or browser it happened on. The group's type, such as `TypeError` or `ReferenceError`, is read from the start of the message; anything else shows as `Error`.

## Read the Errors screen

The date range and filters at the top of the dashboard apply to the whole screen.

### Summary

* **Occurrences**: how many times an error was thrown in the range.
* **Affected visitors**: how many visitors hit at least one error.
* **Error-free sessions**: the share of visits where nothing broke.

When you compare periods, each figure shows its change. Below the figures, a chart shows occurrences over time.

If nothing was recorded, the screen reads **No errors recorded.** with a **Copy snippet** button that copies your script tag with `data-errors` added. If the attribute is already there, nobody hit an error in that period.

### Error groups

The list shows up to 50 groups with the most occurrences in the range. Each row shows the type and message, the source file, when it was first seen, a trend sparkline, occurrences, affected visitors, when it was last seen and its status.

* **Status tabs**: **Open** (the default), **Resolved**, **Ignored** and **All**, each with a count.
* **Search**: matches the error type, the message and the source file.
* **Sort**: by **Last seen** (the default), **Occurrences** or **Affected visitors**.

### Error details

Select a row to open the group's details:

* The full type and message, and the source file.
* **Occurrences**, **Affected visitors**, **First seen** and **Last seen**.
* **Trend over the selected period**.
* **Sample stack trace**: the most recent stack captured for the group. A group can have none: scripts from another origin only share their stack when they are loaded with CORS, and a promise rejected with something other than an `Error` carries no stack.
* **Top pages** and **Browsers**: the five pages and five browsers with the most occurrences. Select one to filter the dashboard by it.

## Resolve, ignore or reopen an error

Owners, admins and members of the site can change an error's status from the details panel:

| Current status | Actions | What happens |
| - | - | - |
| Open | **Resolve** | The group moves to **Resolved**. If the error happens again after you resolved it, CrispStats reopens it by itself. |
| Open | **Ignore** | The group moves to **Ignored**. It keeps being counted, but stays out of the open list and does not reopen. |
| Resolved or ignored | **Reopen** | The group moves back to **Open**. |

Ignored errors also do not trigger **New error** alerts.

## Get alerted about errors

Two alert rules watch errors: **New error** tells you when an error appears that has not been seen before, and **Error spike** tells you when errors pass a count within a window. See [alert rule types](https://docs.crispstats.com/alerts/rule-types.md#new-error).

## Next steps

> [card] [Get alerted](https://docs.crispstats.com/alerts/overview.md)
>
> Send new errors and error spikes to email, Slack, Discord, Telegram or a webhook.

> [card] [Monitor web vitals](https://docs.crispstats.com/health/web-vitals.md)
>
> Measure how fast pages load and respond for real visitors.

> [card] [Content Security Policy](https://docs.crispstats.com/help/content-security-policy.md)
>
> Allow the script and collector if your site sends a CSP header.


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