# Stripe revenue attribution: four ways to tie a payment to a traffic source

The CrispStats team · Published 2026-11-23 · Updated 2026-11-29

**TL;DR:** Revenue attribution for Stripe means joining each payment to the visit, and so the traffic source, that led to it. There are four ways to make the join: put the analytics visitor id in the Checkout Session's metadata, pass it as client_reference_id, match the customer's email to an email you captured on the site, or fire a purchase event from the browser after checkout. Metadata read from the webhook is the most reliable; the browser event is the least, because Stripe itself warns that customers are not guaranteed to reach your success page.

Your analytics knows visitors as anonymous ids with a source attached. Stripe knows customers as payments with an email attached. Revenue attribution is the join between the two, and most of the bugs in revenue reports come from that join, not from the attribution model.

There are four ways to make it. They are not mutually exclusive, and a good setup uses one as the main path and another as a fallback. Each section below says how the method works, what Stripe's documentation says about it, and the specific ways it loses or misfiles revenue. Which visit gets the credit once the join is made is a separate question, covered in [first touch vs last touch](/blog/revenue-attribution-first-touch-vs-last-touch).

## The four methods at a glance

| Method | Where the link lives | Survives renewals | Main failure |
| --- | --- | --- | --- |
| Checkout metadata | `metadata` on the Checkout Session (and `subscription_data.metadata`) | Yes, if set on the subscription too | No id when the analytics script is blocked |
| `client_reference_id` | One string field on the Checkout Session | No, it is not on invoices | Often already used for your own user id |
| Email match | Customer email in Stripe vs an email captured on your site | Yes | Different addresses, personal data handling |
| Browser purchase event | An event sent from your success page | No | Customers who never reach the page; double counts |

## 1. Checkout metadata

Read the visitor id in the browser when the customer clicks buy, send it to your server, and attach it to the Checkout Session as metadata. When the payment succeeds, Stripe sends a `checkout.session.completed` event to your webhook with the session's metadata in it, as the [Stripe metadata docs](https://docs.stripe.com/metadata) describe. Your analytics reads the id back and files the payment under that visitor's source.

```js
// Browser: when the customer clicks "Buy"
const visitorId = await crispstats.id();
await fetch("/api/checkout", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ priceId, visitorId }),
});

// Server: create the session with the id in both places
const session = await stripe.checkout.sessions.create({
  mode: "subscription",
  line_items: [{ price: priceId, quantity: 1 }],
  metadata: { crispstats_visitor_id: visitorId },
  subscription_data: { metadata: { crispstats_visitor_id: visitorId } },
  success_url: "https://example.com/welcome",
  cancel_url: "https://example.com/pricing",
});
```

### How it fails

- **Renewals lose the id.** Stripe states that metadata does not copy automatically between related objects. A Checkout Session's own metadata is not on the subscription, so later invoices arrive without it. Setting `subscription_data.metadata` puts it on the subscription, and Stripe copies subscription metadata to each new invoice as a snapshot, under `parent.subscription_details.metadata`.
- **No id to send.** If an ad blocker stopped the analytics script, there is no id. Send the customer to checkout anyway; the payment is recorded without a visit and usually shows as direct.
- **The id was read on the server.** An id derived from the request has to come from the visitor's browser. Fetching it from your server returns an id for your server.
- **Payment Links.** Metadata on a Payment Link is copied to every session it creates, so it cannot hold a per-visitor id. Use method 2 for Payment Links.
- **Direct PaymentIntents.** If you use Elements instead of Checkout, put the id in the PaymentIntent's metadata and listen for `payment_intent.succeeded`.

## 2. client_reference_id

`client_reference_id` is a single string on the Checkout Session, meant for reconciling a session with your own systems; it is listed on the [Checkout Session object](https://docs.stripe.com/api/checkout/sessions/object). It is the documented way to attach a per-visitor value to a Payment Link: Stripe's [Payment Link URL parameter docs](https://docs.stripe.com/payment-links/url-parameters) allow alphanumeric characters, dashes and underscores up to 200 characters, silently drop invalid values, and send the value in the `checkout.session.completed` webhook.

```js
// Browser: add the visitor id to a Payment Link before opening it
const visitorId = await crispstats.id();
const url = new URL("https://buy.stripe.com/your-link");
if (visitorId) url.searchParams.set("client_reference_id", visitorId);
window.location.href = url.toString();
```

### How it fails

- **One field, many claimants.** Many apps already use `client_reference_id` for their own user or order id. Overwriting it breaks reconciliation; leaving it means no attribution. An analytics tool reading it should ignore values that are not shaped like its own ids.
- **Not on invoices.** It lives on the Checkout Session only, so subscription renewals cannot be attributed through it. Pair it with method 3 or set subscription metadata where you can.
- **Visible in the URL.** On a Payment Link it is part of the address. Stripe warns not to put sensitive data there; an anonymous analytics id is fine, an email is not.

## 3. Email match

Stripe collects the customer's email at checkout (`customer_details.email` on the session). If your site captured an email earlier, on a signup form or a newsletter form, and your analytics stored it against the visitor, you can match the two after the fact. This is how many tools attribute payments that arrived with no id at all.

### How it fails

- **Different addresses.** People sign up with a work address and pay with a personal one, or use a relay address from their mail provider. No match, or a match to the wrong visitor if addresses are shared.
- **Personal data in analytics.** Storing an email next to a browsing history turns anonymous analytics into data about an identifiable person, with the obligations that come with it. Hashing the address before storing it limits exposure, but Recital 26 of the [GDPR](https://eur-lex.europa.eu/eli/reg/2016/679/oj) says pseudonymised data that can be linked back to a person is still personal data. Your own counsel decides what your setup needs.
- **Timing.** The match only works if the email was captured before the payment and kept long enough. A customer who pays on their first visit gives you nothing to match.

Email matching is most useful as a fallback inside your payment data: once a customer's first payment is attributed by id, later payments from the same customer (renewals, upgrades, refunds) can inherit that attribution by matching the email between payments, without the email ever being joined to browsing data.

## 4. Browser purchase event

The simplest method sends a purchase event from the browser on your success page, with the amount and currency. The analytics script already knows the visitor, so no id has to travel through Stripe.

```js
// On the page Stripe redirects to after payment
crispstats.revenue(4900, "USD", { plan: "pro" });
```

### How it fails

- **Customers who never arrive.** Stripe's [fulfilment guide](https://docs.stripe.com/checkout/fulfillment) says you cannot rely on the landing page alone because customers are not guaranteed to visit it: someone can pay and lose their connection before it loads. Every such payment is missing from your revenue report.
- **Delayed payment methods.** Bank debits and transfers complete after checkout, through a later `checkout.session.async_payment_succeeded` event. The success page fires before the money is real, and failed payments stay counted.
- **Double counting.** Reloads, back-button visits and bookmarked success pages fire the event again unless you guard it with the session id.
- **Blocked scripts.** The same ad blockers that hide visits hide the purchase.
- **No renewals or refunds.** Nothing happens in the browser when an invoice renews or a charge is refunded.
- **Anyone can send it.** The amount comes from the browser, so it can be edited. Treat it as a signal, not as bookkeeping.

> **Guard the success page.** If you use the browser event because you cannot add webhooks yet, read the session on your server from the session id in the success URL and fire the event only when its payment status is paid, once per session.

## Which method should you use?

1. **Checkout or Elements with your own server:** metadata as the main path, with `subscription_data.metadata` so renewals keep their source.
2. **Payment Links or a no-code site:** `client_reference_id` added to the link in the browser.
3. **Subscriptions:** add an email match between payments so renewals and refunds inherit the first payment's source when no id is present.
4. **No webhook access at all:** the browser event, guarded by the session id, and expect a gap between your analytics and your Stripe balance.

Whatever you choose, reconcile once a month: total attributed revenue plus unattributed revenue should equal what Stripe shows for the same period, in the same currency. A growing unattributed share is the earliest sign that an id stopped travelling, usually after a checkout change.

## How CrispStats attributes Stripe payments

CrispStats receives Stripe webhooks for Checkout Sessions, subscription invoices, direct PaymentIntents and refunds. It reads the visitor id from the `crispstats_visitor_id` metadata key first, then from `client_reference_id` when that holds a value shaped like a visitor id (32 hexadecimal characters), so user ids and order numbers in that field are ignored. A value of your own that happens to have the same shape would be read as a visitor id, which is why the metadata key is the safer place. The id comes from `crispstats.id()` in the browser. Setup is in the [Stripe integration guide](/integrations/stripe), the [Stripe docs](https://docs.crispstats.com/revenue/stripe) and the guide to [passing the visitor id at checkout](https://docs.crispstats.com/revenue/visitor-id-at-checkout); [Stripe analytics](/analytics/stripe-analytics) shows what the reports look like once payments arrive.

When a renewal or refund arrives with no visitor id, it inherits the attribution of the same customer's earlier attributed payment, matched by a one-way hash of the email address. The full address is never stored: only that hash and a masked form such as j***@e***.co.uk are kept, and neither is matched against browsing data. Payments are credited to the first touch known for the visitor; refunds are recorded as negative payments; new and renewal revenue are reported separately. A payment with no id at all is still counted, as direct. The browser call `crispstats.revenue()` and a server-side payment API cover setups without webhooks. All of it is part of [revenue attribution](/features/revenue-attribution), on every plan.

## How do you reconcile attributed revenue with Stripe?

Once a month, attributed payments plus payments that arrived with no visitor id should equal what Stripe shows for the same charges, in the same currency. Renewals and refunds sit on their own lines. This month is hypothetical, at a $49 price.

Hypothetical. 16 × 49 = 784, 4 × 49 = 196, and 20 × 49 = 980.

| Line | Amount | What it is |
| --- | --- | --- |
| New payments with a visitor id (16) | $784 | Attributed to a source |
| New payments with no visitor id (4) | $196 | Real charges, with no visit to credit |
| New payments together | $980 | The figure to match against Stripe |
| Renewal invoices (10) | $490 | Not new customers |
| Refunds (2) | -$98 | Taken off the original payment |

New charges plus renewals, with refunds taken off, come to $980 + $490 - $98 = $1,372. Setting the $784 of attributed new payments next to $1,372 makes the gap look like lost payments.

**The mistake that changes the number.** The $784 is one line. The four payments without an id, $196, are still revenue, whether a tool files them under a source or leaves them out of the source table. Dropping them, or comparing new attributed revenue with a total that includes renewals, fails the check. After the totals match, [Stripe analytics](/analytics/stripe-analytics) is the breakdown by source. Which visit gets the credit is in [first touch vs last touch](/blog/revenue-attribution-first-touch-vs-last-touch).

## What does a refund do to the channel that was credited?

Take one of those hypothetical $49 payments, credited to organic search because the visitor id was in the Checkout Session metadata. The customer is later refunded in full.

One hypothetical payment. The success-page method misses refunds, as that section describes.

| How the refund is recorded | Organic search after the refund |
| --- | --- |
| A negative payment on the same source | $0 |
| A purchase event only, so the refund never reaches the report | $49 |

**The mistake that changes the number.** The channel still shows $49 after the net for that customer is $0. Two refunds like this leave the channel report $98 above the net. Record the refund on the refund date, against the source of the original payment. The join those reports use is [revenue attribution](/features/revenue-attribution).

## Frequently asked questions

### Should I use metadata or client_reference_id for attribution in Stripe?

Use metadata when you create Checkout Sessions on your server, and also set it in subscription_data.metadata so renewals carry it. Use client_reference_id for Payment Links, where you cannot set per-visitor metadata, or when the field is free.

### Why are my Stripe subscription renewals showing as direct?

Because the renewal invoice has no visit behind it and no visitor id. Stripe does not copy Checkout Session metadata to the subscription. Set subscription_data.metadata at checkout, or let your analytics carry the first payment's source forward to later payments from the same customer.

### Can I attribute Stripe Payment Links to traffic sources?

Yes. Append client_reference_id with the visitor id to the Payment Link URL in the browser before sending the customer there. Stripe returns it in the checkout.session.completed webhook. UTM parameters on the link itself only describe the link, not the visit that led to it.

### Is tracking a purchase on the success page enough?

Not on its own. Stripe's documentation says customers are not guaranteed to reach the landing page, and delayed payment methods succeed after it loads. A webhook-based method records every payment; the success page event misses some and can double count others.

### Do I need to store customer emails to attribute revenue?

No. Passing an anonymous visitor id through the checkout and reading it back from the webhook needs no email. Email matching is a fallback, and a hash of the address is enough to link a customer's payments to each other.

### How do you check attributed Stripe revenue against Stripe?

Add the payments you attributed and the payments that arrived with no visitor id, for the same period and currency, and compare that sum with Stripe's total for those charges. Keep renewal invoices and refunds on separate lines. A gap that grows after a checkout change usually means the visitor id stopped being passed.

### How should a Stripe refund show in an attribution report?

As a negative payment on the date of the refund, credited to the same source as the original payment. A report that only records a purchase event in the browser keeps the original amount, so the channel no longer matches Stripe.
