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

> Connect Superwall with an organization API key, then choose the project and application: CrispStats reads paywall purchases, renewals and refunds and links them to visits through your user id.

Connect Superwall by pasting an organization API key, then choosing the project and the application whose purchases count for this site. CrispStats imports the purchases Superwall keeps, 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 Superwall organization API key, then choose a project and an application |
| New payments | Within seconds when the key may write webhooks, otherwise within 2 minutes |
| History | As far back as Superwall's event log reaches |
| 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 user carries `crispstats_visitor_id` |

## What is recorded

| Superwall event | Recorded as |
| - | - |
| Initial purchase | `subscription_new`. A free trial carries no price and is skipped |
| Renewal | `subscription_renewal`. The renewal that ends a free trial is the first payment, so it is `subscription_new` |
| Product change | `subscription_renewal`, for the amount charged |
| Non-renewing purchase | `one_time` |
| Refund | `refund` of its purchase |

The amount is what the customer paid in their own currency, not Superwall's US dollar figure. Every purchase is read back from Superwall's API with your key before it counts as verified revenue. Purchases from other applications in the project are not counted.

Purchases made through Stripe or a custom store are not counted here, so nothing counts twice. Connect Stripe, or the provider behind your custom store, to CrispStats to count them.

> [!NOTE]
>
> Revenue tracking must be set up in Superwall for purchases to appear. If the project has no purchases yet, the panel says "No purchases yet. Revenue tracking must be set up in Superwall for purchases to appear." and still connects.

## Connect Superwall

**1. Open the Superwall panel**

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

**2. Create the API key**

Under **Superwall API key**, select **Open API keys in Superwall**. It opens your Superwall dashboard. Then:

1. Open **Settings**, then **API keys**, and create a key named CrispStats.
2. Under **Read**, tick **Projects** and **Webhooks**. Under **Write**, tick **Webhooks**.
3. Under **Project access**, choose **Restricted** and pick this app's project.
4. Copy the key and paste it here.

**3. Choose the project and application**

Paste the key. CrispStats checks it with Superwall and lists the projects the key can see under **Project**, then that project's apps under **Application**. With one of each, they are picked for you.

**4. Connect**

Select **Connect Superwall**. With **Write** on **Webhooks**, CrispStats adds one webhook to the project and the row shows **Connected to** your project and application. **Live.** Without it, the row says "Updates every 2 minutes. Add Write on Webhooks to the key to see purchases the moment they happen."

**5. Link purchases to visits**

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

A public SDK key (`pk_`) is refused: "That is a public SDK key. Create an organization API key in Settings, then API keys."

> [!NOTE]
>
> Superwall's documentation does not give the exact labels in the create-key dialog or a prefix for organization keys. The steps above follow Superwall's access-control page; if your dialog reads differently, give the key read access to projects and webhooks, write access to webhooks, and access to this project only.

## What the key can do

| Access | Why |
| - | - |
| Read: Projects | List your projects and their applications |
| Read: Webhooks | Read Superwall's event log, to import history and verify each purchase |
| Write: Webhooks | Add the webhook, and remove it when you disconnect. Optional: without it CrispStats reads the event log every 2 minutes |
| Project access: Restricted | The key sees only this app's project |

CrispStats does not ask for read access to everything: that would include user data and analytics for every project. It never moves money.

## How fresh the numbers are

With the webhook, Superwall sends each purchase within seconds, and CrispStats reads the event log every 10 minutes as a safety net. Without it, CrispStats reads the event log every 2 minutes.

Superwall holds an event whose user it does not know yet for up to 48 hours before sending it, so a few purchases can arrive that late, whichever way they are read. Superwall does not document whether its event log records purchases for a project that has no webhook. If a connection without the webhook stays empty while sales happen, add **Write** on **Webhooks** to the key.

## Past payments

When you connect, CrispStats imports the purchases in Superwall's event log. Superwall does not say how long it keeps them, so the row says how far back the import reached: "Imported from" the date of the oldest purchase Superwall keeps. See [revenue history](https://docs.crispstats.com/revenue/history.md).

## Test mode

Superwall keys have no test mode. Each purchase says whether it was made in the sandbox or production: 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. Identify the customer 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
Superwall.shared.identify(userId: user.id)
```

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

CrispStats uses Superwall's `app_user_id` as the user id unless it is anonymous, and credits the purchase to that user's first visit. 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 user attribute `crispstats_visitor_id` before the paywall opens:

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

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

## Disconnect

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

## 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] [RevenueCat](https://docs.crispstats.com/revenue/revenuecat.md)
>
> Purchases handled by RevenueCat 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.