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

> Connect Freemius with your API Bearer token and Product ID: CrispStats imports past payments, checks for new ones every 2 minutes and supports live and sandbox events.

Connect Freemius by pasting your product's API Bearer Authorization Token and numeric Product ID. CrispStats imports your past payments and refunds, then checks Freemius for new ones every 2 minutes.

| | |
| - | - |
| You paste | Your product's API Bearer token and numeric Product ID |
| New payments | Within 2 minutes |
| History | Every payment, renewal and refund since your first |
| Test mode | Live (`environment: 0`) and sandbox (`environment: 1`) payments separated automatically |
| Linked to a visit | Call `crispstats.identify()` with the Freemius user id in `FS.Checkout` |

## What is recorded

| Freemius payment | Recorded as |
| - | - |
| One-time checkout (`subscription_id` absent) | `one_time` |
| First subscription payment (`is_renewal` false) | `subscription_new` |
| Subscription renewal (`is_renewal` true) | `subscription_renewal` |
| Refund (`type: "refund"`), chargeback, or lost dispute | `refund`, tied to the original payment via `bound_payment_id` |
| Sandbox payment (`environment: 1`) | Kept out of verified revenue with a **Test** badge |

Amounts include tax collected (`gross + vat`) in the payment's own currency. Open or won disputes are skipped because no money was permanently refunded. Free `$0` checkouts are skipped. Each payment is stored once under its Freemius payment id across history imports, polls and optional webhooks.

## Connect Freemius

**1. Open the Freemius panel**

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

**2. Copy your API Bearer token and Product ID**

Open your product in the **Freemius Developer Dashboard**, then go to **Settings**, then **API & Keys**:

1. Copy the **Product ID** shown at the top of the page.
2. Copy the **API Bearer Authorization Token** (generate one if none exists yet).
3. Keep the token active so CrispStats can keep reading payments.

**3. Paste the token and Product ID**

Paste the token into **API Bearer token** and the number into **Product ID**. CrispStats checks them against Freemius at once and reads your product title.

**4. Connect**

Select **Connect Freemius**. CrispStats starts importing past payments and polls Freemius every 2 minutes for new sales, renewals and refunds.

## What the key can do

A Freemius API Bearer token is scoped to the single product you connect. CrispStats uses it only to read payments, plans and customer emails (to carry attribution from initial sales onto renewals and refunds). The token is stored encrypted, used only on CrispStats' servers against `api.freemius.com`, and never shown again.

## Live vs sandbox payments

Freemius uses a single product API token for both production (`environment: 0`) and sandbox (`environment: 1`) payments. CrispStats automatically marks sandbox purchases with a **Test** tag and keeps them out of verified revenue.

## Link visits at checkout

Freemius REST payment responses do not return custom checkout metadata parameters. When embedding **Freemius Checkout** (`FS.Checkout`) on your site, pass the customer's Freemius user id to `identify()` in `purchaseCompleted` so CrispStats ties the purchase to their browsing session:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
handler.open({
  plan_id: "1234",
  purchaseCompleted: function (response) {
    const uid = response?.purchase?.user_id || response?.user?.id;
    if (uid) window.crispstats?.identify(String(uid));
  },
});
```

If customers are already identified with your own application user id, avoid overwriting `identify()` with a different id. Hosted `checkout.freemius.com` redirects that do not invoke `FS.Checkout` on your domain cannot carry a visitor id directly.


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