> ## 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 Creem revenue to CrispStats

> Connect Creem with an API key: CrispStats imports past transactions, creates its webhook when the key allows it, and ties each sale to a visit through the checkout metadata.

Connect Creem by pasting an API key. CrispStats imports your past transactions, creates its own webhook when the key allows it, and records one-time payments, new subscriptions, renewals, refunds and disputes from then on. Put the visitor id in the checkout's metadata and each sale is tied to the visit that led to it.

| | |
| - | - |
| You paste | A Creem API key |
| New payments | Within seconds when the key may write webhooks, otherwise within 2 minutes |
| History | Every transaction since your first. Past one-time sales arrive without a visit |
| Test mode | A key from Creem's test mode connects in test mode |
| Linked to a visit | When `crispstats_visitor_id` is in the checkout `metadata` |

## What is recorded

| Creem object | Recorded as |
| - | - |
| A paid checkout | `subscription_new` when it starts a subscription, otherwise `one_time`. The amount is what the customer paid, tax included. |
| A subscription payment | The first is the same transaction as the checkout and is stored once. Later ones are `subscription_renewal`. |
| A refund | `refund`, for the amount refunded |
| A dispute whose transaction was charged back | `refund` of that transaction |

Each payment is stored under Creem's transaction id, so a sale reported by the checkout and the subscription is stored once. Every payment is read back from Creem's API with your key before it counts as verified revenue.

## Connect Creem

**1. Open the Creem panel**

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

**2. Create the API key**

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

1. Turn off **Test mode** in the sidebar, then open **Developers**.
2. Create a new API key named CrispStats.
3. Give it **Read** on every scope, and **Write** on **Webhooks** so sales show up the moment they happen.
4. Copy the key and paste it here.

**3. Paste the key and connect**

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

With **Write** on **Webhooks**, CrispStats creates one webhook for this site, named CrispStats revenue attribution, and the row 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.

Creem answers the same way for a key it does not know and for a key that cannot read transactions, so the panel says: "Creem did not accept this key, or the key cannot read transactions. Copy the key again in one piece and check it has Read on Transactions, then paste it here."

## What the key can do

| Access | Why |
| - | - |
| Read on every scope | Read and verify transactions, subscriptions and refunds, past and new |
| Write on Webhooks | Create the webhook, and delete it when you disconnect. Optional: without it CrispStats checks every 2 minutes |

Give the key no other write access. CrispStats never moves money. The names of Creem's scopes in the key dialog may differ slightly from the ones above; choose read access everywhere and write access on webhooks only.

## How fresh the numbers are

With the webhook, Creem sends each sale within seconds, and CrispStats checks every 15 minutes as a safety net. Without it, CrispStats reads new transactions every 2 minutes. Refunds of older sales reach a connection without the webhook through a daily check, so they can take up to a day to appear.

## Past payments

When you connect, CrispStats imports every transaction since your first. Creem keeps no checkout metadata for past one-time sales, so those are imported without a visit: they count in revenue but not in the source breakdowns. Past subscription payments take the subscription's metadata. See [revenue history](https://docs.crispstats.com/revenue/history.md).

## Test mode

Creem keeps test and live keys apart, and a test key works only in test mode. A key that only Creem's test environment accepts gets "This is a test key. Test payments show with a Test tag and never count as verified revenue." and the choice of **Connect in test mode** or **Use a live key**.

## Pass the visitor id at checkout

Add the id from `crispstats.id()` to the checkout's `metadata` as `crispstats_visitor_id`:

```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, when you create the checkout
await fetch("https://api.creem.io/v1/checkouts", {
  method: "POST",
  headers: { "x-api-key": process.env.CREEM_API_KEY, "content-type": "application/json" },
  body: JSON.stringify({
    product_id: "prod_...",
    metadata: { crispstats_visitor_id: visitorId },
  }),
});
```

Use your own server key here, not the key you gave CrispStats. In test mode the API is `https://test-api.creem.io`. Renewals and refunds read the id from the subscription, which carries the checkout's metadata. The checkout's `request_id` is read as the visitor id only when it is shaped like one, and the customer's `external_id` is used as your user id when the metadata has none.

## Disconnect

Select **Disconnect** on the Creem row. CrispStats deletes its webhook in Creem and destroys the saved key and signing secret. Payments already recorded stay. If Creem does not let CrispStats remove the webhook, delete the one named CrispStats revenue attribution in Creem, under **Developers**, then **Webhooks**.

> [!NOTE]
>
> Connections made earlier by pasting a webhook 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.