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

# How CrispStats collects and reports data

> Follow an event from the CrispStats script to the collector, the live view and your reports, and learn how visitors, sessions and presence are counted.

CrispStats counts a visit in three stages: the script on your page sends a small event to the collector at `in.crispstats.com`, the collector filters and enriches it at the edge and shows it to anyone watching the live view, and the event is then written to storage, where your reports read it. A visit appears in the live view within seconds and in the overview charts about a minute later. This page explains each stage so you know why numbers can lag, why some requests are never counted, and how visitors and sessions are defined.

## The path of an event

The same path applies to every event the script sends: pageviews, engagement pings, custom events, revenue, identify calls, web vitals and errors.

Back
Next

**1. The script sends the event**

The script builds a small payload: the site's public key, the page URL, the referrer, the screen width, the browser language, the timezone name and a timestamp. The URL fragment is sent only when the script has `data-hash`. The script sends the payload to `https://in.crispstats.com/e` with `navigator.sendBeacon`, or `fetch` with `keepalive` when the beacon is unavailable or refused. The body is JSON sent as `text/plain`, so the browser makes no preflight request, and the script never reads the response. By default the script sets no cookie and writes nothing to the device.

**2. The collector answers 202 at once**

The collector reads the body and replies `202 Accepted` before it looks up the site or does any other work, so tracking never slows your page. The rest happens after the response. Because of this, an unknown key, a bot, a paused site or a payload that fails validation all get the same empty `202`. The only browser-facing errors are `400` for a body that is not a JSON object and `413` for a body over 16 KB.

**3. The collector filters the request**

These requests are dropped without a trace:

* AI crawlers. They are never counted as visits, only when your server reports them (see [AI crawlers](https://docs.crispstats.com/ai/ai-crawlers.md)).
* Bots, headless browsers, HTTP clients, prerender and prefetch requests, and requests without a User-Agent, according to the site's [bot filtering](https://docs.crispstats.com/privacy/bot-filtering.md) level.
* Events from a hostname the site does not allow, from an excluded path or from an excluded IP address. See [exclude traffic](https://docs.crispstats.com/tracking/exclude-traffic.md).
* Events for an unknown key or a paused or suspended site.
* Events for a workspace in its trial that has reached its 25,000 events this month. It is paused until a plan starts or the next month begins.
* Events for a workspace that is locked because it has no plan after its trial or plan ended.
* Anything over the rate limit of 1,200 requests per 60 seconds from one address at one edge location.

On a paid plan, going over the monthly event allowance never drops events. See [plans and limits](https://docs.crispstats.com/account/plans-and-limits.md) for what happens in the trial and on each plan.

**4. The collector enriches the event**

The collector derives the [visitor id](#visitors) from the IP address and User-Agent, reads the device type, browser and operating system from the User-Agent, and estimates the location from the connection, with coordinates rounded to 0.1 degree. It then discards the IP address and User-Agent: neither is stored or logged.

It also cleans the page URL: by default query strings are removed from the stored path, duplicate and trailing slashes are normalised, and a fragment that starts with `#/` or `#!/` is kept as a hash route (the script sends the fragment only with `data-hash`). UTM parameters are read before the query string is removed, and the referrer and UTM tags are classified into a [traffic channel](https://docs.crispstats.com/concepts/metrics.md#traffic-channels).

**5. The site's realtime hub assigns a session**

Each site has one realtime hub. It decides whether the event continues the visitor's current [session](#sessions) or starts a new one, updates who is online, and pushes the event to every open realtime view of the site. This is why the [realtime](https://docs.crispstats.com/dashboard/realtime.md) screen shows a visit within seconds.

If the hub cannot be reached, the event is still stored. It gets a session id derived from the visitor id and a 30-minute time bucket, so it still groups into a visit.

**6. The event is written to storage**

Events are written in batches of up to 100, or whatever arrived within 5 seconds. A failed write is retried with backoff, and delivery is at least once: the database ignores an event it has already stored. Each batch also updates the visit it belongs to (entry page, exit page, pageviews, duration, source) and, for engagement pings, the time on page and scroll depth of the pageview. Pings themselves are not stored as events.

**7. Rollups are refreshed and reports read them**

Every minute, CrispStats recomputes hourly and daily totals for each hour that received events. Reports without filters read these totals, so the overview charts and tables trail live data by about a minute. Reports with a filter, such as a country or a page, read the stored visits directly. So do reports for sites with [persistent visitors](https://docs.crispstats.com/privacy/persistent-visitors.md) and reports viewed in a timezone other than the site's.

### Expected delays

| Where you look | When an event shows up |
| - | - |
| [Realtime](https://docs.crispstats.com/dashboard/realtime.md) screen and the live card on the overview | Within seconds, as soon as the collector processes the event |
| Visitor profiles and filtered reports | Once the event's batch is written, a few seconds after the event (batches are written at least every 5 seconds) |
| Overview KPIs, charts and tables without filters | About a minute after the event (a few seconds for sites with persistent visitors) |

If a visit is in the live view but not yet in the overview, wait a minute and reload. If it never appears in the live view, the request was most likely filtered or blocked before it reached the collector. [Troubleshooting](https://docs.crispstats.com/help/troubleshooting.md) covers the common causes.

## Visitors

A visitor is an anonymous id, not a person. By default the collector computes it as the first 32 hex characters of a SHA-256 hash of a daily random salt, the site id, the IP address and the User-Agent. The salt changes at the start of each day in the site's timezone. The old salt is kept for 35 minutes after its day ends so open sessions can finish, then deleted, so yesterday's ids cannot be recomputed or linked to today's.

This has two consequences for counting:

* **One browser is one visitor per day.** The same person on two devices, or on two networks in the same day, counts as two visitors.
* **Visitors add up across days.** Someone who visits on Monday and on Tuesday counts as one visitor each day, and as two visitors in a report for the whole week.

To keep a session intact across midnight, a session that is still open keeps its visitor id for 30 minutes after midnight in the site's timezone.

If you turn on [persistent visitors](https://docs.crispstats.com/privacy/persistent-visitors.md), the script stores a random id in `localStorage` and sends it with each event, and the collector hashes it with the site id. Returning visitors are then recognised across days, and a report over a date range counts each id once. This stores an identifier on the visitor's device, so read that page before you turn it on.

Events from your server with a secret API key carry no IP address or User-Agent. They join a visit only when you pass a visitor id you got from `crispstats.id()` earlier and that visit is still open, within 30 minutes of its last event. See [server-side events](https://docs.crispstats.com/track/server-side-events.md).

## Sessions

A session is one visit: a run of events from the same visitor. A new session starts when either of these happens:

* **30 minutes of inactivity.** The next event after 30 minutes without one starts a new session.
* **A new campaign or referrer.** A pageview that arrives through a different source, channel or `utm_campaign` than the one the session started with starts a new session, even within 30 minutes. Direct arrivals never split a session. Navigation within one hostname does not either, because a referrer on the page's own hostname, or a subdomain of it, counts as direct. A link from your domain to a page on one of its subdomains, such as from `example.com` to `blog.example.com`, counts as a referral and starts a new session.

Every event in a session carries the session's entry source, so a custom event is credited to the channel that started the visit. Payments are credited differently, see [revenue](#revenue).

Engagement pings keep a session alive. The script sends a ping when the page is hidden or left, and before each single-page navigation, with the seconds the page was visible and the furthest scroll depth. A ping moves the session's last-seen time forward, which is how a one-page visit gets a duration. A ping that arrives more than 30 minutes after the session's last event does not extend it.

Session duration is the time from the session's first event to its last event or ping. See [metrics](https://docs.crispstats.com/concepts/metrics.md) for how bounce rate and visit duration are calculated from sessions.

## Presence

A visitor is online while they have sent an event in the last 5 minutes. The realtime screen, the live card on the overview and the [live visitor badge](https://docs.crispstats.com/share/live-visitor-badge.md) all use this window. When 5 minutes pass without an event, the visitor leaves the live view and the feed shows the end of their visit. While someone has the realtime view open, the online count is refreshed every 5 seconds.

Presence and sessions use different windows. A visitor who reads one page for 10 minutes without scrolling to a new page sends no events while reading, so they drop out of the live view after 5 minutes. When they leave the page, the script sends a ping, and that ping still belongs to the same session because it arrived within 30 minutes.

## Revenue

Payments reach CrispStats in two ways: from the payment providers you connect with a key, which CrispStats reads back from each provider's API (by webhook where the provider sends one, and by a regular check), and revenue events sent with `crispstats.revenue()` or from your server with a secret API key (see the [payment API](https://docs.crispstats.com/revenue/payment-api.md)). Each payment is attributed to the first visit of the customer who paid, found through the visitor id you pass at checkout or the user id you set with `crispstats.identify()`. A renewal or refund that arrives without a visitor reuses the attribution of the same customer's first payment, matched by email address. If the paying visitor's session is still open, within 30 minutes of their last event, the payment also appears in the live feed at once. See [revenue attribution](https://docs.crispstats.com/revenue/overview.md).

## Learn more on crispstats.com

* Features: [realtime](https://crispstats.com/features/realtime) and the [live globe](https://crispstats.com/features/live-globe) are the live view this page describes.
* Glossary: [visitor hash](https://crispstats.com/glossary/visitor-hash), [session](https://crispstats.com/glossary/session) and [bot traffic](https://crispstats.com/glossary/bot-traffic).

## Next steps

> [card] [Metrics explained](https://docs.crispstats.com/concepts/metrics.md)
>
> How visitors, bounce rate, visit duration, conversion rate and channels are calculated.

> [card] [Cookieless tracking](https://docs.crispstats.com/privacy/cookieless-tracking.md)
>
> The privacy model behind the daily visitor id.

> [card] [Collector API](https://docs.crispstats.com/api-reference/collector.md)
>
> The endpoints behind `/e`, `/id` and `/bot`.


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