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

# Raw events

> Page through a site's recorded events, one object per event, with a CrispStats API key that has the admin scope: from, to, cursor and limit, and what each field holds.

Returns the site's own events, one object per event, oldest first. It is the API version of the [raw events download](https://docs.crispstats.com/share/raw-events.md), with the same fields, and it has no limit on how long a period you read: use it for a month with more than 500,000 events, or to read many months at once.

## Access

The endpoint needs a key with the **Admin** scope. A key with only **Read** gets `403 forbidden` with `Raw events need a key with the admin scope. Create one in your workspace settings, under API keys.` Raw events carry the user ids your site sends with `crispstats.identify`, and visitor and session ids, which the dashboard shows only to owners and admins, and only owners and admins can create keys. See [API keys](https://docs.crispstats.com/account/api-keys.md).

Without a key the endpoint answers `401 unauthorized`. The demo site has no raw events: a request for `demo` without a key gets `403 forbidden`.

Each page counts as one request against your plan's daily API allowance. See [rate limits](https://docs.crispstats.com/api-reference/rate-limits.md).

## The period

`from` is required. `from` and `to` each take a day, `YYYY-MM-DD`, read in the site's timezone, or an ISO 8601 timestamp.

* A day in `from` starts at midnight in the site's timezone. A day in `to` includes that whole day.
* A timestamp in `from` is inclusive; a timestamp in `to` is exclusive.
* Without `to`, the period ends now.
* `to` must be after `from`.

The response echoes the resolved period as `from` and `to` timestamps in UTC.

This endpoint takes only `from`, `to`, `cursor` and `limit`. Any other parameter is refused with `400 invalid_request`, which names it.

## Paging

`limit` sets the events per page, from 1 to 10,000, and defaults to 1,000. When a page is full, `nextCursor` holds a cursor: pass it back as `cursor`, with the same `from` and `to`, to read the next page. When `nextCursor` is `null`, you have every event in the period. A full last page can be followed by one empty page.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const base = "https://crispstats.com/api/v1/sites/YOUR_SITE_ID/raw-events";
const headers = { Authorization: `Bearer ${process.env.CRISPSTATS_ADMIN_KEY}` };
const events = [];
let cursor = null;
do {
  const params = new URLSearchParams({ from: "2026-10-01", to: "2026-10-31", limit: "10000" });
  if (cursor) params.set("cursor", cursor);
  const response = await fetch(`${base}?${params}`, { headers });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const page = await response.json();
  events.push(...page.events);
  cursor = page.nextCursor;
} while (cursor);
console.log(`${events.length} events`);
```

The cursor is the time and id of the last event read, and events come in that order, so paging never repeats an event. A cursor that was changed or comes from somewhere else is refused with `400 invalid_request`.

## The events

Each event has the 29 fields of the [raw events columns](https://docs.crispstats.com/share/raw-events.md#columns), in the same order, with these differences from the CSV file:

* `revenue` is in integer minor units, such as `4900` for \$49.00, with its `currency`.
* `props` is the event's properties as a JSON object.
* A value that is not known is `null`.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "site": "8b0c5f3e-6a1d-4f0e-9a51-0c2d7e4b9f10",
  "from": "2026-10-01T00:00:00.000Z",
  "to": "2026-11-01T00:00:00.000Z",
  "events": [
    {
      "timestamp": "2026-10-01T00:00:04.112Z",
      "type": "pageview",
      "name": null,
      "hostname": "example.com",
      "path": "/pricing",
      "referrer_host": "google.com",
      "channel": "organic_search",
      "source": "Google",
      "utm_source": null,
      "utm_medium": null,
      "utm_campaign": null,
      "utm_term": null,
      "utm_content": null,
      "country": "DE",
      "region": "Berlin",
      "city": "Berlin",
      "device": "desktop",
      "browser": "Firefox",
      "os": "macOS",
      "language": "de",
      "duration": 42,
      "scroll": 80,
      "revenue": null,
      "currency": null,
      "props": null,
      "session_id": "c1f0…",
      "visitor_id": "9a2e…",
      "user_id": null,
      "event_id": "0b6c2f8e-1d4a-4c3b-9e7f-2a5d8c1e4b90"
    }
  ],
  "nextCursor": "MjAyNi0xMC0wMVQwMDowMDowNC4xMTJafDBiNmMyZjhl…"
}
```

Days [imported from Plausible](https://docs.crispstats.com/switch/import-from-plausible.md) are daily totals, not events, so this endpoint never returns them.


## OpenAPI

````yaml api-reference/openapi.json GET /sites/{siteId}/raw-events
openapi: 3.1.0
info:
  title: CrispStats API
  version: 1.0.0
  description: >-
    Read-only access to a site's analytics. Authenticate with an API key as a
    bearer token (`Authorization: Bearer cs_sk_…`); the demo site `demo` can be
    read without one. Money is integer minor units in the stated `currency`,
    rates are 0..1, durations are seconds and timestamps are ISO-8601 UTC.
    Limits: a daily allowance per key from the plan, plus 20 requests per 10
    seconds; without a key, 500 requests a day. Every key in a workspace also
    counts toward a workspace ceiling of 5 times the plan's daily allowance,
    shared with the MCP server, where each JSON-RPC request in a POST counts
    once and a batch may hold at most 20 requests. Every response carries
    `X-RateLimit-*` headers, and a 429 carries `Retry-After`.
servers:
  - url: https://crispstats.com/api/v1
security:
  - apiKey: []
  - {}
tags:
  - name: Sites
  - name: Analytics
  - name: Raw data
paths:
  /sites/{siteId}/raw-events:
    get:
      tags:
        - Raw data
      summary: Raw events
      description: >-
        The site's own events, one object per event, oldest first, in pages of
        up to 10,000. Pass `nextCursor` back as `cursor` until it is null. Needs
        a key with the admin scope: raw events carry the user ids your site
        sends with identify(), and visitor and session ids. Money is integer
        minor units in `currency`.
      operationId: listRawEvents
      parameters:
        - name: siteId
          in: path
          required: true
          description: >-
            The site's id, from GET /sites. Unlike the reports, raw events need
            a key even for the public demo site `demo`.
          schema:
            type: string
        - name: from
          in: query
          required: true
          description: >-
            Start: a day (YYYY-MM-DD, in the site's timezone) or an ISO
            timestamp, inclusive.
          schema:
            type: string
        - name: to
          in: query
          required: false
          description: >-
            End: a day (inclusive, the whole day) or an ISO timestamp
            (exclusive). Defaults to now.
          schema:
            type: string
        - name: cursor
          in: query
          required: false
          description: '`nextCursor` from the previous page.'
          schema:
            type: string
        - name: limit
          in: query
          required: false
          description: Events per page, 1 to 10000.
          schema:
            type: integer
            minimum: 1
            maximum: 10000
            default: 1000
      responses:
        '200':
          description: One page of events.
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
          content:
            application/json:
              schema:
                type: object
                required:
                  - site
                  - from
                  - to
                  - events
                  - nextCursor
                properties:
                  site:
                    type: string
                  from:
                    type: string
                    format: date-time
                  to:
                    type: string
                    format: date-time
                  events:
                    type: array
                    items:
                      $ref: '#/components/schemas/RawEvent'
                  nextCursor:
                    type:
                      - string
                      - 'null'
        '400':
          $ref: '#/components/responses/InvalidRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  headers:
    X-RateLimit-Limit:
      description: Requests allowed per day for this caller.
      schema:
        type: integer
    X-RateLimit-Remaining:
      description: Requests left today.
      schema:
        type: integer
    X-RateLimit-Reset:
      description: When the daily allowance resets, as Unix seconds.
      schema:
        type: integer
    Retry-After:
      description: Seconds to wait before retrying.
      schema:
        type: integer
  schemas:
    RawEvent:
      type: object
      description: >-
        One recorded event. Money is integer minor units in `currency`; `props`
        is the event's properties object.
      properties:
        timestamp: {}
        type: {}
        name: {}
        hostname: {}
        path: {}
        referrer_host: {}
        channel: {}
        source: {}
        utm_source: {}
        utm_medium: {}
        utm_campaign: {}
        utm_term: {}
        utm_content: {}
        country: {}
        region: {}
        city: {}
        device: {}
        browser: {}
        os: {}
        language: {}
        duration: {}
        scroll: {}
        revenue: {}
        currency: {}
        props: {}
        session_id: {}
        visitor_id: {}
        user_id: {}
        event_id: {}
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              enum:
                - invalid_request
                - unauthorized
                - forbidden
                - not_found
                - method_not_allowed
                - rate_limited
                - internal_error
            message:
              type: string
              description: What went wrong and how to fix it.
            fields:
              type: object
              additionalProperties:
                type: string
              description: 'On validation errors: the problem with each parameter.'
  responses:
    InvalidRequest:
      description: A parameter is missing or not valid. `fields` says which.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: invalid_request
              message: >-
                range: Invalid option: expected one of
                "today"|"yesterday"|"24h"|"7d"|"30d"|"90d"|"mtd"|"last_month"|"ytd"|"12m"|"all"
    Unauthorized:
      description: No key was sent for a site that needs one, or the key is not valid.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthorized
              message: >-
                That API key is not valid. It may have been revoked or expired.
                Create a new one in your workspace settings, under API keys.
    Forbidden:
      description: The key lacks the read scope or is limited to another site.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: forbidden
              message: That API key is limited to one site, and this is not it.
    NotFound:
      description: The site, funnel or visitor does not exist, or this key cannot read it.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: not_found
              message: That site was not found, or this key does not have access to it.
    RateLimited:
      description: The caller is over its rate limit.
      headers:
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: rate_limited
              message: Too many requests at once. Wait 4 seconds and try again.
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        An API key that starts with cs_sk_, created in your workspace settings,
        under API keys.

````

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