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

# Date ranges, filters, comparison and pagination

> Choose a period with range or from and to, compare with the previous period or year, filter with dimension:op:value, set granularity and page through results.

Most CrispStats API endpoints take the same query parameters for the period, the comparison and filters, plus a few of their own for sorting and paging. This page lists them all with their exact values and limits. A parameter an endpoint does not take is refused with `400 invalid_request` and the list of parameters it does take, so a typo such as `rang=7d` never silently returns the default period.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://crispstats.com/api/v1/sites/demo/breakdown/source?range=30d&compare=previous&filter=country:is:DE&sort=revenue&limit=5"
```

## Period

Pick the period with a preset in `range`, or with a custom `from` and `to`. Passing both is an error.

**range** `string` (default: 30d)

A preset period. One of the values in the table below.

**from** `string`

First day of a custom period, inclusive, as `YYYY-MM-DD` in UTC. Requires `to`.

**to** `string`

Last day of a custom period, inclusive, as `YYYY-MM-DD` in UTC. Requires `from`, and must be the same day as `from` or later. A period that would end in the future ends now.

| `range` | Period |
| - | - |
| `today` | From midnight UTC today until now. |
| `yesterday` | The whole of yesterday, UTC. |
| `24h` | The last 24 hours until now. |
| `7d` | Today and the 6 days before it. |
| `30d` | Today and the 29 days before it. This is the default. |
| `90d` | Today and the 89 days before it. |
| `mtd` | From the first day of this month until now. |
| `last_month` | The whole previous calendar month. |
| `ytd` | From January 1 of this year until now. |
| `12m` | From the first day of the month 11 months ago until now. |
| `all` | All data, from January 1, 2020 until now. |

Days start and end at midnight UTC. Every response echoes the resolved period in `range`, with `from` inclusive, `to` exclusive and a readable `label`:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ "preset": "custom", "from": "2026-10-01T00:00:00.000Z", "to": "2026-11-01T00:00:00.000Z", "label": "Oct 1 – Oct 31, 2026" }
```

These combinations are refused with `400 invalid_request`:

| Request | Message |
| - | - |
| `range=7d&from=2026-10-01&to=2026-10-31` | Pass either range or from and to, not both. |
| `from=2026-10-01` | A custom period needs both from and to. |
| `from=2026-10-31&to=2026-10-01` | to must be the same day as from, or later. |
| `range=forever` | The list of valid presets. |

## Comparison

**compare** `string` (default: none)

`previous` compares with the period just before, of the same length. `year` compares with the same dates one year earlier. `none` turns comparison off.

With a comparison, metrics come back as `{ "value", "previous", "change" }`, where `change` is a ratio: `0.12` is +12% and `-0.1` is -10%. Without one, `previous` and `change` are `null`. Breakdown rows get a `change` in visitors, and the timeseries endpoint adds a `previous` array of points.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://crispstats.com/api/v1/sites/demo/stats?range=7d&compare=previous"
```

## Filters

Narrow any report to a segment with one or more `filter` parameters. Each has the form `dimension:op:value`. Repeat the parameter to add filters; all of them must match.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -G "https://crispstats.com/api/v1/sites/demo/stats" \
  --data-urlencode "range=30d" \
  --data-urlencode "filter=country:is:DE" \
  --data-urlencode "filter=page:contains:/blog"
```

**filter** `string[]`

`dimension:op:value`, repeatable, up to 10. `f` is accepted as another name for `filter`, so you can copy filters from a dashboard URL.

| Part | Values |
| - | - |
| `dimension` | `page`, `entry_page`, `exit_page`, `hostname`, `channel`, `source`, `referrer`, `utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, `utm_content`, `country`, `region`, `city`, `browser`, `os`, `device`, `language`, `event`, `ai_assistant` |
| `op` | `is` and `is_not` match the whole value. `contains` matches part of it. |
| `value` | 1 to 200 characters. Everything after the second colon, so a value may contain colons. |

Use values exactly as they appear in a breakdown row's `key`: a two-letter country code such as `DE`, a source name such as `Google`, a path such as `/pricing`. URL-encode values that contain spaces, `&`, `#` or `+`.

The realtime, funnel list and visitor journey endpoints take no filters; sending one returns `400` with "This endpoint does not take filters." A malformed filter returns `400` with the list of dimensions and operators.

## Imported history

When a site has history [imported from Plausible](https://docs.crispstats.com/switch/import-from-plausible.md), four endpoints include those days by default, as the dashboard does: `/stats`, `/timeseries`, `/breakdown/{dimension}` and `/events`.

**imported** `boolean` (default: true)

`false` leaves imported days out, so the numbers cover only what CrispStats recorded. `true` is the same as leaving it out.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://crispstats.com/api/v1/sites/YOUR_SITE_ID/stats?range=12m&imported=false" \
  -H "Authorization: Bearer $CRISPSTATS_API_KEY"
```

* Imported days are always left out while a `filter` is on: the export has daily totals, not visits.
* Imported days end the day before the first day CrispStats recorded traffic for the site, so a day is never counted twice.
* Imported visitors are counted per day, as CrispStats counts its own in the default privacy mode.
* Imported days have no hostnames, regions or cities, and no event properties.
* Other endpoints never include imported days, and do not take `imported`.
* With `granularity=hour`, a period that holds imported days is returned by day instead; the response's `granularity` says which.

`GET /sites` tells you whether a site has imported history and which days it covers, in each site's `imported` field. It is `null` for a site without an import:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "imported": {
    "source": "plausible",
    "from": "2024-01-01",
    "to": "2026-11-24",
    "recordedFrom": "2026-11-25",
    "importedAt": "2026-11-25T10:14:03.000Z",
    "omitted": ["hostname", "region", "city"]
  }
}
```

| Field | Meaning |
| - | - |
| `source` | Where the history came from. Always `plausible`. |
| `from` | The first imported day the reports use, `YYYY-MM-DD` in the site's timezone. |
| `to` | The last imported day the reports use. |
| `recordedFrom` | The first day the site recorded itself; imported days always end before it. `null` while nothing has been recorded. |
| `importedAt` | When the import finished. |
| `omitted` | Breakdown dimensions that imported days do not fill. |

## Granularity

`GET /sites/{siteId}/timeseries` buckets the period by `granularity`.

**granularity** `string`

`hour`, `day`, `week` or `month`. The default depends on the period length: `hour` up to 2 days, `day` up to 92 days, `week` up to 366 days, then `month`.

A request that would return more than 400 buckets is refused with `400 invalid_request`, for example `range=all&granularity=hour`. Choose a coarser granularity or a shorter period. Visitors are unique within each bucket, so they do not add up across buckets: use `GET /stats` for a period total. The last bucket may carry `"partial": true` while it is still filling.

## Endpoint parameters

Each endpoint's own parameters, besides the period, comparison and filters. Numbers outside the bounds return `400 invalid_request`.

| Endpoint | Parameter | Values | Default |
| - | - | - | - |
| `/breakdown/{dimension}` | `sort` | `visitors`, `pageviews`, `revenue`, `conversionRate`, `bounceRate`, highest first | `visitors` |
| | `limit` | 1 to 100 rows | 10 |
| | `offset` | 0 to 100000 | 0 |
| | `search` | 1 to 100 characters; only values that contain this text | none |
| `/payments` | `limit` | 1 to 100 payments | 20 |
| | `offset` | 0 to 100000 | 0 |
| `/visitors` | `segment` | `all`, `customers`, `identified`, `online`, `returning` | `all` |
| | `sort` | `lastSeen`, `revenue`, `sessions`, `pageviews` | `lastSeen` |
| | `search` | 1 to 100 characters; matches the handle, identity or place | none |
| | `limit` | 1 to 100 visitors | 20 |
| | `offset` | 0 to 100000 | 0 |
| `/visitors/{visitorId}` | `sessions` | 1 to 20 recent sessions | 5 |
| `/events` | `limit` | 1 to 100 events | 25 |
| `/events/{event}/properties` | `limit` | 1 to 50 values per property | 10 |
| `/funnels/{funnelId}` | `segmentBy` | Any filter dimension | none |
| `/retention` | `interval` | `day`, `week`, `month` | `week` |
| `/vitals` | `limit` | 1 to 50 pages | 10 |
| `/errors` | `status` | `open`, `resolved`, `ignored` | all |
| | `limit` | 1 to 50 error groups | 10 |
| `/uptime` | `limit` | 1 to 100 incidents | 20 |
| `/ai-traffic` | `limit` | 1 to 50 rows per list | 10 |

`GET /sites`, `/realtime` and `/funnels` take no parameters at all. `/visitors/{visitorId}` takes only `sessions`, with no period or filters.

The `{dimension}` path segment of a breakdown takes the same dimension names as filters. An unknown dimension returns `400`.

## Pagination

Three endpoints page with `limit` and `offset`. Each response says how many rows exist in total:

| Endpoint | Total field | Order |
| - | - | - |
| `/breakdown/{dimension}` | `totalRows` | By `sort`, highest first |
| `/payments` | `total` | Newest first |
| `/visitors` | `total` | By `sort` |

To read every row, increase `offset` by `limit` until `offset` reaches the total:

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const base = "https://crispstats.com/api/v1/sites/YOUR_SITE_ID/payments";
const headers = { Authorization: `Bearer ${process.env.CRISPSTATS_API_KEY}` };
const payments = [];
for (let offset = 0; ; offset += 100) {
  const response = await fetch(`${base}?range=last_month&limit=100&offset=${offset}`, { headers });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const page = await response.json();
  payments.push(...page.rows);
  if (offset + page.rows.length >= page.total || page.rows.length === 0) break;
}
console.log(`${payments.length} payments`);
```

Other lists are capped and do not page: for example `/realtime` returns the top 5 pages, sources and countries and the 10 most recent events, `/retention` the 12 most recent cohorts, and `/goals` and `/funnels` up to 50 entries. Each page request counts against your [rate limit](https://docs.crispstats.com/api-reference/rate-limits.md).

## Next steps

> [card] [Errors](https://docs.crispstats.com/api-reference/errors.md)
>
> Read the `fields` object on validation errors.

> [card] [Rate limits](https://docs.crispstats.com/api-reference/rate-limits.md)
>
> Budget requests when you page through large reports.

> [card] [Filters in the dashboard](https://docs.crispstats.com/dashboard/filters-and-comparison.md)
>
> The same filters and comparisons, applied in the dashboard.


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