# Count your Stripe sales

> Link every Stripe sale to the visit that brought it: Checkout by its success URL, and Payment Links, Buy Buttons and Pricing Tables by a read-only key.

Link every Stripe sale to the visit that brought it, so your dashboard shows which sources bring paying customers.

## Before you start

[Install CentPath](https://centpath.app/docs/install) first: a sale counts only on a page that loads the snippet.

## 1. Tell CentPath how buyers pay you

1. In CentPath, open your site and go to **Setup** → **Sales**.
2. Under **How do buyers pay you?**, pick **Stripe Checkout** if your site creates a Checkout Session, or **Stripe Payment Link** if you sell through Payment Links, Buy Buttons or Pricing Tables. Setup shows the steps for the one you pick.

## 2. Mark the Checkout success URL

With **Stripe Checkout**, add this to the end of your Checkout success URL:

```text
?session_id={CHECKOUT_SESSION_ID}
```

1. Open the code that creates the Checkout Session, and find its success URL.
2. Add the line above to its end. If the URL already has a ?, start with & instead.
3. Make sure the success page loads the CentPath snippet: it reads the id when the buyer lands there.

Stripe fills in the id, and each sale counts once. Without a Stripe key, a sale counts with no amount.

With **Stripe Payment Link**, there is nothing to add to your pages. The snippet tags each Payment Link, Buy Button and Pricing Table, and stores nothing on the visitor's device. Your Stripe key is how we see these sales, so go on to the next step.

## 3. Add a read-only key

With a read-only key we list your Stripe sales and renewals and their amounts, even ones whose buyer never came back to your site.

1. In your Stripe Dashboard, open the **API keys** page, at `dashboard.stripe.com/apikeys`. Make the key in live mode to count your real sales: a key reads only the mode it was made in.
2. Click **Create restricted key**. If Stripe offers a preset set of permissions, start from zero permissions instead.
3. In **Key name**, type a name you will know it by, like CentPath.
4. Set Checkout Sessions, PaymentIntents and Invoices to **Read**, and leave every other permission at **None**. Read access is all it needs: we only ever read from your account.
5. Click **Create key**, and complete the verification Stripe sends you.
6. Click the key's value to copy it: Stripe shows it only once. Then click **Done**.
7. In **Setup** → **Sales**, paste it into **Stripe key** under **Read-only key**, then click **Save key**.

We encrypt it and never show it again. We list your completed checkouts and renewal invoices and keep only each order's id, amount, currency and time, never who bought.

## Verify the setup

1. Make a real purchase, or wait for your next sale. A key reads one Stripe mode: a live key (`rk_live_…`) lists live sales alone, and only a test-mode key (`rk_test_…`) lists a test-mode purchase, with **Test-mode key: only Stripe test-mode sales are listed** under the sync line.
2. In **Setup** → **Sales**, the line under the key says when sales last synced. The first sync runs within 10 minutes of saving the key.
3. Open your dashboard and switch the chart to **Revenue**: the sale is there, under the source of the visit that brought it.

## Troubleshooting

### A sale shows with no amount

Without a Stripe key, a Checkout sale counts as an order with no amount. Add a read-only key, as in step 3, and its amount is read from Stripe.

### Setup asks for a restricted key, not your secret key

You pasted your secret key (`sk_…`). Create a restricted key as in step 3: it starts with `rk_`.

### A test purchase doesn't show

Your key is a live key (`rk_live_…`), which lists live sales alone: Stripe keeps its test mode apart. Only a test-mode key (`rk_test_…`) lists a test-mode purchase. Make a real purchase, or wait for your next sale.

### Setup says renewals aren't counted

Your key lacks Invoices: read. On Stripe's **API keys** page, open the key's ⋯ menu, choose **Edit key** and set Invoices to **Read**. There is nothing to paste again.

### Setup says it couldn't reach Stripe

The line says why, and CentPath retries on its own. If it says the key needs a permission, open the key's ⋯ menu on Stripe's **API keys** page, choose **Edit key** and set that permission to **Read**.

### The dashboard says a sale is not linked to a visit

Nothing ties the sale to a visit: the buyer's browser blocked the script, say, or they paid through Checkout and never came back to your success page. The sale counts on the line under the figures, never in a source's revenue. [How revenue is counted](https://centpath.app/docs/revenue#sales-not-linked-to-a-visit) explains the line.

### You sell with PayPal or your own checkout

In **Setup** → **Sales**, pick **Something else**. On your thank-you page, call:

```js
window.analytics.goal("purchase", {
  revenueMinorUnits: 4900, // 49.00 USD, in its smallest unit
  currency: "USD",
  id: orderId, // counts each sale once
});
```

No code? Put the order id in your thank-you URL. The sale counts, without an amount:

```text
?ap_order=ORDER_ID
```

[Count sales from any checkout](https://centpath.app/docs/other-checkouts) has the details.
