Skip to content

Revenue

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

Checkout metadata, client_reference_id, email matching and a browser purchase event: how each ties a Stripe payment to a visit, and how each one fails.

The CrispStats team · · 9 min read

In short

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.

The four methods at a glance

The four methods at a glance
MethodWhere the link livesSurvives renewalsMain failure
Checkout metadatametadata on the Checkout Session (and subscription_data.metadata)Yes, if set on the subscription tooNo id when the analytics script is blocked
client_reference_idOne string field on the Checkout SessionNo, it is not on invoicesOften already used for your own user id
Email matchCustomer email in Stripe vs an email captured on your siteYesDifferent addresses, personal data handling
Browser purchase eventAn event sent from your success pageNoCustomers 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 describe. Your analytics reads the id back and files the payment under that visitor’s source.

// 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 placesconst 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. It is the documented way to attach a per-visitor value to a Payment Link: Stripe’s Payment Link URL parameter docs allow alphanumeric characters, dashes and underscores up to 200 characters, silently drop invalid values, and send the value in the checkout.session.completed webhook.

// Browser: add the visitor id to a Payment Link before opening itconst 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 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.

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

How it fails

  • Customers who never arrive. Stripe’s fulfilment guide 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.

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, the Stripe docs and the guide to passing the visitor id at checkout; 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, on every plan.

Guide questions. Straight answers.

What people ask after reading this.

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

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

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

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

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

Not answered here? Write to hello@crispstats.com

Go further

Free tools

  • Bounce rate calculator

    Calculate bounce rate from sessions, under the classic single-page rule or the GA4 definition, and see how many bounces stand between you and a target.

  • Conversion rate calculator

    Work out your conversion rate from visitors and conversions: conversions ÷ visitors × 100.

  • Engagement rate calculator

    Calculate engagement rate the GA4 way for a website, or the social media way for a post by reach, impressions or followers, and see why the two differ.

Use cases

  • CrispStats for SaaS

    See which channels bring paying customers, where trials stall in the funnel, and how your app performs for real users, from one cookieless script.

  • CrispStats for indie hackers

    Traffic, revenue by source, uptime and errors for every side project in one dashboard.

  • CrispStats for ecommerce

    Tie orders to the campaign, page and source they came from, find where checkout loses people, and watch page speed, without cookies.

Your traffic, crisp and clear

One script, no cookies, and every feature from the first day. Set up takes about as long as pasting a snippet.