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

# Monitor Core Web Vitals from real visits

> Measure LCP, INP, CLS, FCP and TTFB in your visitors' browsers with data-vitals, then read the score, percentiles and slowest pages on the Performance screen.

CrispStats measures Core Web Vitals in the browsers of your real visitors. Add `data-vitals` to the script tag, and each page load reports Largest Contentful Paint, Interaction to Next Paint, Cumulative Layout Shift, First Contentful Paint and Time to First Byte. The **Performance** screen turns those samples into a score, percentiles and a list of your slowest pages.

## Turn on web vitals

Add the `data-vitals` 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-vitals
  src="https://in.crispstats.com/d.js"
></script>
```

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

Deploy the change, open a page on your live site, then switch to another tab or close the page. Vitals are sent when the page is hidden, so the first numbers appear on **Performance** under **Health** in the site's sidebar after real visitors have loaded and left a few pages.

Until any sample arrives, the screen shows **No web vitals yet.** with a **Copy snippet** button that copies your script tag with `data-vitals` already added.

## How each metric is measured

The script follows the web-vitals definitions without loading the web-vitals package. It sends one event of type `vitals` per page load, the first time the page is hidden, and attributes it to the URL the page loaded with.

| Metric | What it measures | How the script measures it |
| - | - | - |
| **LCP**, Largest Contentful Paint | How long until the biggest thing on screen, usually the headline or hero image, has loaded. | The last `largest-contentful-paint` candidate. Browsers stop emitting candidates at the first input, and the script stops at the first hide. |
| **INP**, Interaction to Next Paint | How quickly the page reacts when someone clicks, taps or types. | The worst interaction, skipping one interaction for every 50 (close to the 98th percentile of interactions on that page). |
| **CLS**, Cumulative Layout Shift | How much the layout jumps around while the page loads. | The largest session window: shifts less than 1 second apart, 5 seconds at most per window. Shifts right after user input are ignored. |
| **FCP**, First Contentful Paint | How long until the first text or image shows up. | The `first-contentful-paint` paint entry. |
| **TTFB**, Time to First Byte | How long your server takes to start answering. | `responseStart` of the navigation. |

A few rules apply to every sample:

* Times are in milliseconds, measured from activation, so a prerendered page is not charged for the time before it was shown.
* CLS is a unitless score. The script sends it multiplied by 1000, and the dashboard shows it as the score again (for example `0.05`).
* FCP and LCP are left out for a page that loaded in a background tab, because nothing meaningful was painted.
* Only the metrics the browser supports are sent. A browser without layout-shift support sends no CLS, for example.
* A page excluded with `data-exclude` sends nothing.

## Thresholds

CrispStats rates every value with the Core Web Vitals thresholds. A value up to the first bound is **Good**, a value above the second bound is **Poor**, and anything in between **Needs improvement**.

| Metric | Good up to | Poor above |
| - | - | - |
| LCP | 2.5 s | 4 s |
| INP | 200 ms | 500 ms |
| CLS | 0.1 | 0.25 |
| FCP | 1.8 s | 3 s |
| TTFB | 800 ms | 1.8 s |

LCP, INP and CLS are the three Core Web Vitals. FCP and TTFB help you explain them: a slow TTFB delays everything after it.

## Read the Performance screen

The date range and filters at the top of the dashboard apply to the whole screen. See [filters and comparison](https://docs.crispstats.com/dashboard/filters-and-comparison.md).

### Core Web Vitals score

The score ring shows a number from 0 to 100: the share of measured page loads where LCP, INP and CLS were all good at once. Each page load sends one sample, and it passes when every core vital it reported is within the good bound, so a page load that reported only LCP is judged on LCP alone. The ring is rated:

* **Good** at 75 or more, because Google grades a page at the 75th percentile.
* **Needs improvement** from 50 to 74.
* **Poor** below 50.

Next to the ring, LCP, INP and CLS each show their own rating, or **No data** when no sample reported that metric.

### One card per metric

Each metric has a card with:

* The 75th percentile (p75) for the range, with the number of samples.
* The change from the previous period, when you compare periods. A drop is shown as an improvement.
* A sparkline of the p75 over the range.
* A bar that splits the samples into good, needs improvement and poor.

Select a card to show that metric in the detail chart below. LCP is selected by default.

### Percentiles over time

The detail section charts the selected metric's p75 for each minute, hour, day, week or month of the range (the bucket size follows the range), with lines at the good and poor bounds. While every point is good, the poor line is hidden; select it in the legend to show it.

Switch between **p50**, **p75** and **p90** to read the typical visit, what Google grades, or the slow tail. The chart line is always the p75 of each bucket; p50 and p90 are measured over the whole range and drawn as a flat reference line.

### By page, device and country

* **By page** lists the 20 pages with the most samples, with the p75 of LCP, INP, CLS and TTFB and an overall rating. The rating is the worst of the page's LCP, INP and CLS ratings. Sort by any column to find the slowest pages.
* **By device** shows the same p75 values for each device type (desktop, mobile, tablet).
* **By country** shows LCP and TTFB for the 20 countries with the most samples. Distance from your servers usually shows up in TTFB first.

Select a row in any of these tables to filter the whole dashboard by that page, device or country.

If a filter leaves no samples, the screen reads **No measurements match these filters.** Widen the range or remove a filter.

## Get alerted when the site gets slower

A **Web vitals regression** alert watches the p75 of LCP, INP, FCP or TTFB over a window you choose and notifies you once when it crosses your limit. See [alert rule types](https://docs.crispstats.com/alerts/rule-types.md#web-vitals-regression).

## Next steps

> [card] [Track JavaScript errors](https://docs.crispstats.com/health/errors.md)
>
> Collect uncaught errors and rejected promises from the same script.

> [card] [Alert rule types](https://docs.crispstats.com/alerts/rule-types.md)
>
> Set a limit on LCP, INP, FCP or TTFB and get told when it is crossed.

> [card] [Script attributes](https://docs.crispstats.com/tracking/script-attributes.md)
>
> Every optional module and option the script reads.


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