> ## Documentation Index
> Fetch the complete documentation index at: https://developers.scrunch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Referrals API: Send traffic from any analytics tool

> Send daily AI referral traffic from Adobe Analytics, a warehouse or any other analytics tool, and see it in Scrunch's AI Referrals, Explorer and Scrunchie.

## Overview

Send Scrunch the visits your website gets from AI assistants (ChatGPT, Perplexity, Claude, Gemini and others), straight from the analytics tool you already use: Adobe Analytics, a data warehouse, a log pipeline, anything that can count daily sessions by referrer and page.

You send one row per day, referrer and page. Scrunch shows it on the **AI Referrals** page, and in the **Explorer** and **Scrunchie** where AI referrals are on for your brand.

> [!WARNING]
>
> **Beta.** Talk to your Scrunch team before you build against this API: they turn it on for your brand and help you set it up. Until it's on, every endpoint returns `404`.

> [!NOTE]
>
> Using **Google Analytics 4**? Connect it in **Integrations** instead; you don't need this API. A website reads from one source at a time, so a website with Google Analytics connected can't also use this API (and the other way around).

***

## How it works

1. **Register the website.** One call per website returns a `connection_id`.
2. **Send daily rows** to that connection, on whatever schedule suits you: a daily job, a pipeline, or several times a day. Sending a row again replaces it, so retries and corrections are safe.
3. **See the data** in Scrunch. A day shows once it's over (UTC).

All endpoints live under `https://api.scrunchai.com/v1`.

| Method | Path | What it does |
| - | - | - |
| `POST` | `/{brand_id}/ai-referrals/connections` | Register a website. |
| `GET` | `/{brand_id}/ai-referrals/connections` | List the brand's connections and their last push or error. |
| `DELETE` | `/{brand_id}/ai-referrals/connections/{connection_id}` | Disable a connection: its data stops showing and new rows are refused. |
| `POST` | `/{brand_id}/ai-referrals/connections/{connection_id}/events` | Send rows. |

***

## Authentication

Send an API key as a Bearer token. Create one in Scrunch under **API Keys**:

* `configure` scope to register, disable and send rows.
* `query` scope to list connections.

```bash theme={null}
export SCRUNCH_API_TOKEN="your-key"
```

***

## Register a website

```bash theme={null}
curl -X POST "https://api.scrunchai.com/v1/1234/ai-referrals/connections" \
  -H "Authorization: Bearer $SCRUNCH_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"website": "example.com", "provider": "custom"}'
```

* `website` must be one of the brand's websites in Scrunch.
* `provider` is a label for where the data comes from: use `"custom"` for any tool. `"adobe_analytics"` is also accepted. Both are read the same way.

The response includes the connection `id`: use it as `connection_id` when you send rows. Each website has one active connection at a time.

***

## Send rows

Send a JSON array (`Content-Type: application/json`) or one row per line (`Content-Type: application/x-ndjson`), up to **10,000 rows** and **5 MB** per call, and up to **120 calls a minute** per brand.

```bash theme={null}
curl -X POST \
  "https://api.scrunchai.com/v1/1234/ai-referrals/connections/01JX2Y6E8H1AKQ8V0W7G4D9SXT/events" \
  -H "Authorization: Bearer $SCRUNCH_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '[
    {
      "date": "2026-05-20",
      "raw_referrer_value": "chatgpt.com",
      "raw_page_value": "/pricing",
      "sessions": 298,
      "pageviews": 412,
      "transactions": 7,
      "purchase_revenue": 1842.50,
      "currency_code": "USD"
    },
    {
      "date": "2026-05-20",
      "raw_referrer_value": "perplexity.ai",
      "raw_page_value": "/blog/launch-notes",
      "sessions": 71,
      "pageviews": 88
    }
  ]'
```

```json theme={null}
{ "accepted": 2, "rejected": 0, "errors": [] }
```

A row whose referrer isn't an AI assistant (`google.com`, say) is counted in `rejected` with its reason in `errors`; the rest of the call still goes through.

### Row fields

| Field | Type | Required | Description |
| - | - | - | - |
| `date` | `YYYY-MM-DD` | Yes | The UTC day the row covers. Not in the future, at most five years back. |
| `raw_referrer_value` | string | Yes | The referrer as your tool reports it, e.g. `chatgpt.com`. Don't map it yourself: Scrunch matches it to the AI assistant. |
| `raw_page_value` | string | Yes | The landing page, as a path (`/pricing`) or a full URL. Stored as sent; Scrunch reads it by its path, without the query. |
| `sessions` | integer | No | Sessions from that referrer on that page that day. |
| `pageviews` | integer | No | Page views in those sessions. |
| `transactions` | integer | No | Purchases in those sessions. |
| `purchase_revenue` | number | No | Revenue from those purchases. |
| `currency_code` | string | With revenue | ISO 4217 code of the revenue, e.g. `USD`. Required when `purchase_revenue` isn't 0. A connection keeps one currency. |
| `users` | integer | No\* | Users who arrived from that referrer that day. |
| `new_users` | integer | No\* | Of those, users new to the website. At most `users`. |
| `engaged_sessions` | integer | No\* | Engaged sessions, by your tool's definition. At most `sessions`. |
| `engagement_seconds` | number | No\* | Total engagement time of the row's sessions, in seconds. |
| `key_events` | integer | No\* | Conversion events in the row's sessions. |
| `converted_sessions` | integer | No\* | Sessions with at least one conversion. At most `sessions`. |
| `batch_id` | string | No | Your own id for the run that sent the row, to trace it later. |

\* **All six or none.** Send `users`, `new_users`, `engaged_sessions`, `engagement_seconds`, `key_events` and `converted_sessions` together on every row, or leave all six out. Leave them out and Scrunch shows traffic and revenue only for that website. A connection keeps the choice its first rows made: to change it, disable the connection, register the website again and send its history the new way.

**Replacing rows.** A row is identified by `date`, `raw_referrer_value` and `raw_page_value`. Sending the same three again replaces the earlier values. Pages are compared as sent, so `https://www.example.com/pricing` and `/pricing` are two rows (both count as `/pricing` in Scrunch).

***

## Status codes

| Status | Meaning |
| - | - |
| `200` | Rows received. The body says how many were `accepted` and `rejected`, and why. |
| `201` | Website registered. |
| `400` | The body isn't valid JSON or NDJSON, the provider or website isn't valid, or one call mixes rows with and without the six optional fields, or two currencies. |
| `404` | The brand or connection doesn't exist, or the API isn't on for the brand yet. |
| `409` | The website already has an active connection or Google Analytics connected, or the rows don't match what the connection already sends (the six optional fields, or the currency). |
| `410` | The connection is disabled. Register the website again. |
| `413` | More than 10,000 rows or 5 MB. Split the call. |
| `422` | Some rows aren't valid. Nothing from the call is stored; `detail.errors` lists each bad row by its number. |
| `429` | More than 120 calls a minute for the brand. Nothing is stored; wait the seconds in the `Retry-After` header and send it again. |

When a call stores nothing because of its rows (a `400`, `409` or `422`, or every row rejected), the reason is kept on the connection as `last_push_error`, and `last_pushed_at` says when rows last arrived. Listing connections shows both; the next call that stores rows clears the error.

***

## Tips

* **Send finished days.** A day shows in Scrunch once it's over; re-send a day if your tool revises it.
* **Retry freely.** Sending the same rows again replaces them, so a retry never double-counts.
* **Keep raw values.** Send referrers and pages as your tool reports them.
* **Set `batch_id`** to tie rows to the run that sent them.


## Related topics

- [Register AI Referrals Connection](https://developers.scrunch.com/api-reference/ai-referrals/register-ai-referrals-connection.md)
- [Scrunch REST API Directory and Authentication](https://developers.scrunch.com/api-reference/introduction.md)
- [List AI Referrals Connections](https://developers.scrunch.com/api-reference/ai-referrals/list-ai-referrals-connections.md)


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