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

> Connect RevenueCat with a v2 secret API key: CrispStats imports App Store and Google Play purchases, adds its webhook when the key allows it, and links purchases to visits through your user id.

Connect RevenueCat by pasting a secret API key (v2). CrispStats reads your project's App Store and Google Play purchases, adds its own webhook when the key allows it, and records new subscriptions, renewals, one-time purchases and refunds. Sign customers in with the same id in your app and on your site, and each purchase is linked to their first visit.

| | |
| - | - |
| You paste | A RevenueCat secret API key, version 2 |
| New payments | Within seconds when the key may write integrations, otherwise once a day |
| History | Every purchase of every customer in the project |
| Test mode | Per purchase: sandbox purchases show with a **Test** tag |
| Linked to a visit | When the app's user id matches the id your site passes to `identify`, or the customer carries `crispstats_visitor_id` |

## What is recorded

| RevenueCat event | Recorded as |
| - | - |
| A first paid subscription purchase | `subscription_new`. A free trial is skipped; the renewal that ends it is the first payment |
| A renewal | `subscription_renewal` |
| A non-renewing purchase | `one_time` |
| A refund made through the store's customer support | `refund` |

Every purchase is read back from RevenueCat's API with your key before it counts as verified revenue. Amounts are in the purchase's own currency. Each purchase is stored under its store transaction id, so a purchase seen by webhook, import and check is stored once.

Purchases through Web Billing and Stripe are counted through Stripe, and Paddle purchases through Paddle, if you connect them, so nothing counts twice. PayPal purchases made through RevenueCat are not counted.

## Connect RevenueCat

**1. Open the RevenueCat panel**

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

**2. Create the secret API key**

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

1. Open your project's settings, then **API keys**, and choose **New**.
2. Name it CrispStats and choose version 2.
3. Under **Customer information**, set **Customers**, **Subscriptions** and **Purchases** to **Read only**.
4. Under **Project configuration**, set **Projects** to **Read only** and **Integrations** to **Read and write**, so CrispStats can add its webhook.
5. Leave everything else at **No access**, choose **Generate**, then copy the key and paste it here.

**3. Paste the key**

Paste the key. CrispStats checks it with RevenueCat and shows the project's name under **Project**. A v2 key belongs to one project, so there is nothing to choose.

**4. Connect**

Select **Connect RevenueCat**. With **Integrations: Read and write**, CrispStats adds one webhook to the project and the row shows **Connected to** your project. **Live.** Without it, the row says "Updates every day. Set Integrations to Read and write to see purchases as they happen."

**5. Link purchases to visits**

See [link purchases to visits](#link-purchases-to-visits) below.

A public SDK key (`appl_`, `goog_`, `amzn_` or `rcb_`) is refused: "That is a public SDK key. Create a secret API key (v2) instead." A key that lacks a permission is refused with the permission and the level it needs.

> [!NOTE]
>
> The permission names above are the ones RevenueCat's API documentation uses. The labels in RevenueCat's key dialog may read slightly differently; choose read-only access to customers, subscriptions, purchases and projects, and read and write on integrations.

## What the key can do

| Permission | Why |
| - | - |
| Customers, Subscriptions, Purchases: Read only | Read each customer's purchases, to import history and verify each purchase |
| Projects: Read only | Read the project's id and name |
| Integrations: Read and write | Add the webhook, and remove it when you disconnect. Optional: without it CrispStats reads purchases once a day |

CrispStats does not ask for Charts: charts are totals, not purchases, so they could never be verified. It cannot grant entitlements, change products or refund anything, and it never moves money.

## How fresh the numbers are

With the webhook, RevenueCat sends each purchase within seconds, and CrispStats reads every customer once a week as a safety net. If CrispStats cannot be reached, RevenueCat retries five times over about 80 minutes.

RevenueCat has no list of recent purchases to check, so without the webhook CrispStats reads every customer in the project once a day. A pass reads about 30 customers a minute to stay within RevenueCat's limits, so on a project with many thousands of customers a pass can take longer than a day. Add **Integrations: Read and write** to see purchases as they happen.

Refunds of subscription renewals arrive only by webhook: RevenueCat's API does not mark them, so a connection without the webhook misses them. Refunds of one-time purchases are found either way.

## Past payments

When you connect, CrispStats reads every customer of the project and imports their purchases. Progress shows as "Reading customers:" and the number of purchases found so far. See [revenue history](https://docs.crispstats.com/revenue/history.md).

## Test mode

RevenueCat keys have no test mode. Each purchase says whether it was made in the sandbox: sandbox purchases show with a **Test** tag and never count as verified revenue.

## Link purchases to visits

An in-app purchase does not start on your website, so most purchases are linked through your own user id. Sign the customer in with the same id in the app and on your site:

```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
// In the app (iOS), when the customer signs in
let (customerInfo, created) = try await Purchases.shared.logIn(user.id)
```

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
// On your site, when the same customer signs in
crispstats.identify(user.id);
```

RevenueCat sends `app_user_id` with every purchase, and CrispStats uses it as the user id unless it is an anonymous RevenueCat id (`$RCAnonymousID:`). The purchase is then credited to the first visit of that user. See [identify users](https://docs.crispstats.com/track/identify-users.md).

When the app knows the visitor id, for example from a link on your site that opens the app, set it as the subscriber attribute `crispstats_visitor_id`, and every later event carries it:

```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
Purchases.shared.attribution.setAttributes(["crispstats_visitor_id": visitorId])
```

A purchase with neither is still recorded and counted, without a visit.

## Disconnect

Select **Disconnect** on the RevenueCat row. CrispStats removes its webhook from the project and destroys the saved key. Payments already recorded stay. If RevenueCat does not let CrispStats remove it, delete the webhook named CrispStats revenue attribution in RevenueCat, under **Integrations**, then **Webhooks**.

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

## Next steps

> [card] [Identify users](https://docs.crispstats.com/track/identify-users.md)
>
> Use the same user id on your site and in your app.

> [card] [Superwall](https://docs.crispstats.com/revenue/superwall.md)
>
> Paywalls from Superwall instead.

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