Platforms

How to track Stripe Checkout and Payment Links sales by source

Tie Stripe Checkout and Payment Links sales to the ad, email or post that brought the buyer, count each sale once, and stop Stripe showing up as a source.

On this page

Stripe Checkout and Payment Links send the buyer to a page on Stripe's domain, then back to you. Stripe records the payment perfectly. What it does not know is which ad, email or post brought the buyer, and your analytics, which does know, never sees the payment page. This page joins the two.

What goes wrong by default

  • The sale has no source. The payment happens on checkout.stripe.com or buy.stripe.com, where your analytics does not run.
  • Stripe becomes a source. The buyer returns to your thank-you page from Stripe, so the visit can look like a referral from Stripe, and the ad loses the sale. See cross-domain tracking.
  • The thank-you page misses sales. Stripe itself warns that a buyer can pay and lose connection before the success page loads, and recommends a webhook for fulfillment (Stripe).

Install Sporetag for Stripe Checkout

  1. Add the Sporetag tag to your site, on every page including the thank-you page.
  2. In Sporetag, open your site's tracking health. If Stripe starts visits, tap Count them as my site, so a buyer's return trip keeps its source.
  3. On a paid plan, connect Stripe with a read-only restricted key: open Integrations, then Stripe, and follow the steps in the Stripe connector guide.
  4. Add a goal on the Purchase event. Stripe sales reach it on the date they happened.
  5. To tie each sale to the visits before it, have your server copy the _st_id cookie into the Checkout Session's metadata.st_id. This needs 90-day tracking.

Tie the sale to the visit

There are three ways, from least to most code.

The success page. Put {CHECKOUT_SESSION_ID} in your success URL. Stripe swaps in the real session id after payment (Stripe):

Code
https://yourshop.com/thanks?session_id={CHECKOUT_SESSION_ID}

The thank-you page sends a purchase event with that id as its event_id. The event joins the visit that is already running, so it carries the visit's source. It misses buyers who never reach the page.

Metadata on the session. When your server creates the Checkout Session, add the visitor's first-party analytics id to metadata. The payment then carries it, and a tool reading Stripe can tie the payment to the visits before it, even when the buyer never returned.

The webhook. Your server receives checkout.session.completed and sends the purchase from there, with the same event_id. Combined with the success page, each sale is counted once, and none is lost.

Some payment methods, such as bank debits, can take 2 to 14 days to confirm, so listen for the later webhooks too (Stripe).

Payment Links have no server of yours in the middle, but two settings help:

  • Redirect after payment. Under After the payment, choose to redirect to your own page instead of Stripe's confirmation. The redirect URL can include {CHECKOUT_SESSION_ID} (Stripe).
  • UTM tags carry through. UTM tags on the payment link's own address are added to your redirect URL when the payment completes (Stripe). A payment link shared in a bio with ?utm_source=instagram&utm_medium=social lands the buyer on your thank-you page with those tags.

Stripe also accepts client_reference_id on a payment link's address, up to 200 characters, and returns it in the checkout.session.completed webhook (Stripe). Use it if your own server matches orders.

A worked example

Example numbers, made up for illustration. A course creator sells a $199 course with Stripe Checkout. In a month, Stripe records 52 payments.

MethodSales with a known source
Thank-you page event only44: eight buyers closed the tab or paid by a slower method
Thank-you page plus webhook, same event_id52, with 44 of them carrying the visit's source
Plus metadata.st_id on the session52, nearly all with their source, including the eight

None of the three counts a sale twice, because every path uses the session id.

Common questions

How do I track Stripe Checkout conversions in analytics?

Send a purchase event from your success page with the Checkout Session id from {CHECKOUT_SESSION_ID}, send the same id from your checkout.session.completed webhook, and treat Stripe's checkout pages as part of your site so the return visit keeps its source.

Why does checkout.stripe.com show up as a referral?

Buyers return from Stripe's page to yours, so the referrer is Stripe. Mark Stripe's domains as part of your site in your analytics.

Partly. Set the link to redirect to your own page, add UTM tags to the payment link's address, and they carry through to the redirect. Your thank-you page can then count the sale with its source.

Does Sporetag work with Stripe?

Yes. The Stripe connector reads payments, refunds and subscriptions with a read-only restricted key, on paid plans. It refuses full secret keys.

Sources

Spotted something wrong or out of date? Email hello@sporetag.com and we will fix it.