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

# How revenue attribution works in CrispStats

> How CrispStats ties each payment to the visitor id passed at checkout, credits the first visit's source, and what the Revenue screen shows.

CrispStats attributes each payment to the visit that led to it. Your checkout carries the visitor's anonymous id, CrispStats reads the payment from your payment provider, and credits the payment to the source, campaign and landing page of that visitor's first visit. The Revenue screen then shows which traffic pays.

To set it up you do two things:

1. Connect a payment provider in **Settings**, **Integrations** by pasting a key: [Stripe](https://docs.crispstats.com/revenue/stripe.md), [Polar](https://docs.crispstats.com/revenue/polar.md), [Paddle](https://docs.crispstats.com/revenue/paddle.md), [Dodo Payments](https://docs.crispstats.com/revenue/dodo.md), [Creem](https://docs.crispstats.com/revenue/creem.md), [Whop](https://docs.crispstats.com/revenue/whop.md), [Razorpay](https://docs.crispstats.com/revenue/razorpay.md), [Lemon Squeezy](https://docs.crispstats.com/revenue/lemon-squeezy.md), [Shopify](https://docs.crispstats.com/revenue/shopify.md), [RevenueCat](https://docs.crispstats.com/revenue/revenuecat.md), [Superwall](https://docs.crispstats.com/revenue/superwall.md), [App Store](https://docs.crispstats.com/revenue/app-store.md) or [Shopify App Store](https://docs.crispstats.com/revenue/shopify-app-store.md). CrispStats creates its webhook where the key allows it, checks for new payments on a schedule, and [imports the payments made before you connected](https://docs.crispstats.com/revenue/history.md). Or report payments yourself with the [payment API](https://docs.crispstats.com/revenue/payment-api.md).
2. [Pass the visitor id to your checkout](https://docs.crispstats.com/revenue/visitor-id-at-checkout.md), so each payment can be matched to a visit.

A payment that cannot be linked to a visit is still recorded and counted in revenue, MRR and every total. It is left out of the source, campaign and channel breakdowns rather than filed under **Direct**, so **Direct** only ever holds payments from visitors who really arrived directly.

## From visit to payment

**1. A visitor arrives**

The script records where the visit came from: source, channel, referrer, UTM campaign tags and the landing page.

**2. You pass the visitor id at checkout**

Before you send the visitor to checkout, `crispstats.id()` returns the anonymous id their events are filed under right now. You attach it to the checkout as `crispstats_visitor_id` in the checkout's metadata, custom data or notes (on Shopify, a cart attribute; in a mobile app, your own user id, see [RevenueCat](https://docs.crispstats.com/revenue/revenuecat.md) and [Superwall](https://docs.crispstats.com/revenue/superwall.md)). On Stripe, `client_reference_id` is the alternative when you do not use it for your own ids.

**3. CrispStats reads the payment**

The provider sends the payment to the collector by webhook, or CrispStats finds it on its next check. Either way CrispStats reads it back from the provider's API with your key, so it counts as verified, and reads the visitor id out of the metadata. Every way of seeing a payment gives it the same id, so each charge is stored once. **Settings**, **Integrations** shows when each provider last updated, or why it stopped.

**4. CrispStats joins the payment to the visit**

The payment is stored with the first-touch source, channel, campaign and landing page of that visitor, the number of visits before paying, and the time from the first visit to the payment.

## First-touch attribution

A payment counts for the source, campaign and landing page of the customer's **first** visit, not the visit in which they paid. CrispStats finds that visit like this:

1. **Who paid.** The payment carries the visitor id from checkout, and a user id if you passed `crispstats_user_id` in the checkout metadata. If the visitor is still on your site when the webhook arrives, the payment is also linked to their open session, and takes the user id from `crispstats.identify()` if one was set on that session.
2. **Your user id first.** When the payment has a user id, the earliest session of that user is the first touch.
3. **Then the visitor id.** Otherwise, the earliest session filed under the visitor id is the first touch.
4. **Stored profiles.** If the visitor's stored profile (an identified user, or a visitor on a site with persistent visitors) remembers a first visit older than those sessions, that visit is the first touch.
5. **The customer's earlier payments.** A payment that arrives with neither a visitor id nor a user id, such as many renewals and refunds, takes the attribution of the customer's earliest attributed payment with the same email address (matched by a hash of the address).

Sessions that started up to one hour after the payment time are considered, because a webhook can arrive slightly before the paying pageview is stored.

> [!NOTE]
>
> With the default cookieless setup the visitor id changes every day (UTC), so a visitor id only reaches back to visits on the same day. To credit visits from earlier days, identify signed-in users with [`crispstats.identify()`](https://docs.crispstats.com/track/identify-users) and pass their user id at checkout, or turn on [persistent visitors](https://docs.crispstats.com/privacy/persistent-visitors.md). Without either, a customer who browsed on Monday and paid on Thursday is credited to Thursday's first visit.

## Live feed for online payers

If the paying visitor is still online when the payment arrives, the sale also appears in the [realtime](https://docs.crispstats.com/dashboard/realtime.md) feed next to their session. Refunds are attached to the open session but are not shown as a new sale.

## The Revenue screen

Open **Revenue** in the site's sidebar. Until the site has recorded its first payment, the screen explains attribution and links to **Connect a payment provider**. Once a provider is connected but nothing has been paid yet, it reads **Connected. Waiting for the first payment.**

The date range and filters at the top apply to every section. Filters narrow the payments like this:

* **Channel, source, referrer, UTM source, medium and campaign, landing page and AI assistant** match the payment's first touch.
* **Country, region, city, device, browser and OS** match the visit in which the customer paid, or their latest visit before the payment.
* **Page, event, exit page, hostname, UTM term and content, and language** keep the payments of visitors who had a matching visit in the range.

See [filters and comparison](https://docs.crispstats.com/dashboard/filters-and-comparison.md).

### Summary

Eight figures, with the change against the previous period while comparison is on:

| Figure | What it counts |
| - | - |
| **Revenue** | All payments in the range except refunds. |
| **New revenue** | One-time payments and first subscription payments. |
| **Renewals** | Subscription renewal payments. |
| **MRR** | For each subscriber, their latest subscription payment if it was made in the 31 days before the end of the range, summed. |
| **Customers** | Distinct paying customers (by visitor id, then user id). |
| **Average order** | Revenue divided by the number of payments. |
| **Revenue per visitor** | Revenue divided by visitors in the range. |
| **Conversion rate** | First payments in the range (a customer's first one-time or new subscription payment) divided by visitors, at most 100%. |

Under the figures, one line shows **Refunds**, revenue **After refunds**, and the **Median time to first payment** in days (or **Same day**).

### Standouts

Up to four tiles answer the main question first: the source that **Earns the most**, the source that **Pays best per visitor** (only among sources with at least 30 visitors, or 0.2% of all visitors if that is more, and at least two first payments), the **Top campaign** and the **Top landing page**. Select a tile to filter the dashboard to that value.

### Revenue over time

A bar chart of revenue per period (the period, such as an hour, a day or a month, follows the date range), with visitors as a line. When every payment in the range is loaded (up to 10,000), each bar is split into **New revenue** and **Renewals**. With comparison on, the previous period is drawn as a dashed line.

### Where the revenue comes from

Five cards break revenue down, each row showing revenue, visitors and revenue per visitor:

* **Sources**: by first-touch channel, source or referrer.
* **Campaigns**: by first-touch UTM campaign, source or medium.
* **Landing pages**: by first-touch landing page.
* **Countries** and **Devices**: by the visit in which the customer paid, or their latest visit before the payment.

Select a row to filter the whole dashboard to it.

### Time to convert

Two distributions over the one-time and new subscription payments in the range. Renewals and refunds are left out.

* **Days to first payment**: same day, 1 to 3 days, 4 to 7 days, 8 to 30 days, over 30 days.
* **Visits before paying**: 1, 2, 3, 4, or 5 or more sessions, including the paying one.

The heading line states the share of customers who paid on the day they arrived, and how many times the median customer visited before paying.

### Payments

Every payment in the range, newest first, 25 per page. Each row shows the time, amount, kind (**New**, **Renewal**, **One-time** or **Refund**), product and provider, the customer's visitor name and masked email, the first-touch source and campaign, the landing page, and the time to pay with the number of visits. Filter by kind with **All**, **New**, **Renewals**, **One-time** and **Refunds**, and sort by time, amount or time to pay.

**Export CSV** in the top bar downloads the payments of the current view. See [refunds, renewals and payment types](https://docs.crispstats.com/revenue/refunds-and-renewals.md#export-payments-as-csv) for the columns.

## Next steps

> [card] [Pass the visitor id](https://docs.crispstats.com/revenue/visitor-id-at-checkout.md)
>
> Get the id in the browser and attach it to your checkout.

> [card] [Connect Stripe](https://docs.crispstats.com/revenue/stripe.md)
>
> Paste a restricted key; CrispStats does the rest.

> [card] [Payment types](https://docs.crispstats.com/revenue/refunds-and-renewals.md)
>
> How new payments, renewals and refunds are recorded.


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