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

> Connect Lemon Squeezy with an API key and choose your store: CrispStats imports past orders, creates its webhook and ties each order to a visit through checkout custom data.

> [!WARNING]
>
> Lemon Squeezy closes on 31 March 2027. When you move to Stripe, connect Stripe here too. After that date Lemon Squeezy can no longer be connected; payments already recorded stay.

Connect Lemon Squeezy by pasting an API key and choosing your store. CrispStats imports your past orders and subscription payments, creates its own webhook on the store, and records orders, renewals and refunds from then on. Put the visitor id in the checkout's custom data and each order is tied to the visit that led to it.

| | |
| - | - |
| You paste | A Lemon Squeezy API key, then choose the store |
| New payments | Within seconds, by webhook. A check every 15 minutes catches anything the webhook missed |
| History | Every order since your first |
| Test mode | A key made in test mode connects in test mode |
| Linked to a visit | When `crispstats_visitor_id` is in the checkout's custom data |

## What is recorded

| Lemon Squeezy object | Recorded as |
| - | - |
| A paid order | `one_time`, including the first payment of a subscription (see below) |
| A subscription payment after the first | `subscription_renewal` |
| A refund of an order or subscription payment | `refund`. Lemon Squeezy reports the total refunded so far, so CrispStats records the difference from the last total it saw |

Every order is read back from Lemon Squeezy's API with your key before it counts as verified revenue. The product is the first item's product and variant name, and the customer's email is hashed and masked before storage.

> [!NOTE]
>
> A Lemon Squeezy order does not say whether it started a subscription, so the first payment of a subscription is recorded as `one_time`. It counts toward **Revenue** and **New revenue**; the subscription counts toward **MRR** from its first renewal.

## Connect Lemon Squeezy

**1. Open the Lemon Squeezy panel**

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

**2. Create the API key**

Under **Lemon Squeezy API key**, select **Create an API key in Lemon Squeezy**. Then:

1. Choose the **+** next to **API keys**.
2. Name it CrispStats and pick the latest expiry date offered.
3. Copy the key and paste it here.

The key is a long code that starts with `eyJ`.

**3. Paste the key and choose the store**

Paste the key. CrispStats checks it with Lemon Squeezy and lists your stores under **Store**. With one store it is picked for you.

**4. Connect**

Select **Connect Lemon Squeezy**. CrispStats creates one webhook on the store and the row shows **Connected to** your store. **Live. Lemon Squeezy closes on 31 March 2027.**

**5. Pass the visitor id at checkout**

See [pass the visitor id at checkout](#pass-the-visitor-id-at-checkout) below.

## What the key can do

Lemon Squeezy keys cannot be limited: a key can do anything the API can, including refunds and cancelling subscriptions. CrispStats only reads payments and creates one webhook. The key is stored encrypted, used only on CrispStats' servers with Lemon Squeezy's API, and never shown again.

Lemon Squeezy keys expire. The panel reads the expiry date from the key: an expired key is refused with "This key expired on" its date, and 14 days before a saved key expires the row asks for a new one. Create it with the latest expiry date offered and paste it on the row.

## How fresh the numbers are

Lemon Squeezy sends each order within seconds, and CrispStats checks for new orders and subscription payments every 15 minutes as a safety net. A daily check of the last 48 hours catches refunds on older orders. An order seen more than once is stored once.

## Past payments

When you connect, CrispStats imports every order, subscription payment and refund of the chosen store since your first. See [revenue history](https://docs.crispstats.com/revenue/history.md).

## Test mode

Lemon Squeezy has separate test and live keys. A key made in test mode 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 custom data 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();

// A hosted checkout link: add the id as custom data
const url = new URL("https://your-store.lemonsqueezy.com/buy/your-variant");
if (visitorId) url.searchParams.set("checkout[custom][crispstats_visitor_id]", visitorId);
window.location.href = url.toString();
```

When you create the checkout through the Lemon Squeezy API, put it in `checkout_data.custom`:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ "checkout_data": { "custom": { "crispstats_visitor_id": "<visitor id>" } } }
```

An order without it is still recorded and counted, without a visit.

## Disconnect

Select **Disconnect** on the Lemon Squeezy row. CrispStats deletes its webhook on the store and destroys the saved key and signing secret. Payments already recorded stay. If Lemon Squeezy does not let CrispStats remove the webhook, delete it in Lemon Squeezy, under **Settings**, then **Webhooks**: it keeps sending sales until it is removed.

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

## Next steps

> [card] [Connect Stripe](https://docs.crispstats.com/revenue/stripe.md)
>
> Moving off Lemon Squeezy: connect Stripe to the same site.

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