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

# Connect Dodo Payments revenue to CrispStats

> Connect Dodo Payments with an API key: CrispStats imports past payments and refunds, creates its webhook when the key allows it, and ties each payment to a visit through metadata.

Connect Dodo Payments by pasting an API key. CrispStats imports your past payments and refunds, creates its own webhook when the key allows it, and records payments, subscription charges, refunds and lost disputes from then on. Put the visitor id in the payment's `metadata` and each payment is tied to the visit that led to it.

| | |
| - | - |
| You paste | A Dodo Payments API key |
| New payments | Within seconds when the key may write webhooks, otherwise within 2 minutes |
| History | Every payment since your first |
| Test mode | A `dodo_test_` key connects in test mode |
| Linked to a visit | When `crispstats_visitor_id` is in the payment or subscription `metadata` |

## What is recorded

| Dodo Payments object | Recorded as |
| - | - |
| A succeeded payment with a total above zero | `one_time` without a subscription. With one, the first charge of the subscription is `subscription_new` and later ones are `subscription_renewal`. |
| A succeeded refund | `refund`, for the refund's amount |
| A dispute the business lost or accepted | `refund` of the disputed payment |

Every payment is read back from Dodo Payments' API with your key before it counts as verified revenue. Each carries the currency, the time and the customer's email, hashed and masked before storage. Dodo payments are stored without a product name.

## Connect Dodo Payments

**1. Open the Dodo Payments panel**

In CrispStats, open the site's **Settings**, then **Integrations**. Select **Connect a payment provider** and choose **Dodo Payments**.

**2. Create the API key**

Under **Dodo Payments API key**, select **Open API keys in Dodo Payments**. Then:

1. Open **Developer**, then **API keys**, and choose **Create new key**.
2. Name it CrispStats. Set **Payments**, **Refunds**, **Subscriptions** and **Products** to **Read**.
3. Set **Webhooks** to **Write** so sales show up the moment they happen.
4. Copy the key and paste it here.

The link opens your Dodo Payments dashboard. Dodo does not publish a direct link to the API keys page, so follow the menu from there.

**3. Paste the key and connect**

Paste the key. CrispStats checks it with Dodo Payments at once. Select **Connect Dodo Payments**.

With **Webhooks: Write**, CrispStats creates one webhook for this site, named CrispStats revenue attribution, and the row shows **Connected to** your business name, then **Live.** When Dodo does not return the name, it shows **Connected. Live.** Without it, the row says "Updates every 2 minutes. Add Write on Webhooks to the key to see sales the moment they happen."

**4. Pass the visitor id at checkout**

See [pass the visitor id at checkout](#pass-the-visitor-id-at-checkout) below.

A key made before Dodo added the `dodo_live_` and `dodo_test_` prefixes still connects: the server that accepts it tells test from live. Another provider's key pasted here is refused with a message naming that provider.

## What the key can do

| Permission | Why |
| - | - |
| Payments: Read | Read and verify each payment, past and new |
| Refunds: Read | Read refunds, past and new |
| Subscriptions: Read, Products: Read | Read-only access the help card asks for alongside payments. Today CrispStats reads only payments, refunds and disputes with the key |
| Webhooks: Write | Create the webhook, and delete it when you disconnect. Optional: without it CrispStats checks every 2 minutes |

Leave **Customers** and everything else at **None**. CrispStats never moves money.

## How fresh the numbers are

With **Webhooks: Write**, Dodo Payments sends each payment within seconds, and CrispStats checks every 15 minutes as a safety net. Without it, CrispStats reads new payments and refunds every 2 minutes.

Dodo Payments limits API calls per business across all its keys. CrispStats' checks use a small part of that, and pause when Dodo asks them to slow down. Without the webhook, a lost dispute is found by a daily check of the last 48 hours, so it can take up to a day to appear.

## Past payments

When you connect, CrispStats imports every succeeded payment and refund since your first. See [revenue history](https://docs.crispstats.com/revenue/history.md).

## Test mode

A key that starts with `dodo_test_` connects to Dodo's test environment. The panel says "This is a test key. Test payments show with a Test tag and never count as verified revenue." and offers **Connect in test mode** or **Use a live key**.

## Pass the visitor id at checkout

Add the id from `crispstats.id()` to the `metadata` of the payment, subscription or checkout session you create:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
// In the browser, before you send the visitor to checkout
const visitorId = await crispstats.id();

// On your server, in the body of the payment or subscription you create
const body = {
  // ...your product cart and customer
  metadata: { crispstats_visitor_id: visitorId },
};
```

The payment's metadata is merged over the customer's metadata. A payment without a visitor id is still recorded and counted, without a visit.

## Disconnect

Select **Disconnect** on the Dodo Payments row. CrispStats deletes its webhook in Dodo Payments and destroys the saved key and signing secret. Payments already recorded stay. If Dodo does not let CrispStats remove the webhook, the message asks you to delete the webhook named CrispStats revenue attribution in Dodo Payments, under **Developer**, then **Webhooks**.

> [!NOTE]
>
> Connections made earlier by pasting a webhook signing secret keep working. They cannot import history or verify payments: connect again with a key to add both.

## Next steps

> [card] [Pass the visitor id](https://docs.crispstats.com/revenue/visitor-id-at-checkout.md)
>
> When there is no id, and attributing across days.

> [card] [Refunds and renewals](https://docs.crispstats.com/revenue/refunds-and-renewals.md)
>
> How payment kinds are recorded across providers.

> [card] [Revenue history](https://docs.crispstats.com/revenue/history.md)
>
> What the import reads and how it avoids counting twice.


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