Skip to content

Connect your revenue

How to track Stripe revenue by traffic source

By Brian Lovett, Founder, theBizness.ai · Updated · 4 min read

Stripe is very good at the money side: every charge, subscription, refund and invoice is recorded precisely. What it does not know is the marketing side. A Stripe payment does not tell you that the buyer first arrived from a YouTube video, or that they clicked your newsletter the morning they paid. To see revenue by traffic source, you have to join Stripe’s records with your site’s visit data.

Why it does not work out of the box

  • Hosted checkout breaks the referrer. When a buyer comes back from Stripe Checkout to your success page, the browser reports Stripe as the referrer. A basic analytics setup then credits the sale to Stripe itself.
  • Payments happen later. Many buyers visit several times before paying, so the visit that matters is often days old by the time the charge happens.
  • Renewals have no visit. A subscription renews on Stripe’s schedule, with nobody on your site. Recurring revenue has to inherit its source from the original purchase.

Three common approaches

  1. Do it yourself. Save the visitor’s UTM tags and referrer in your own database at sign-up, copy them into Stripe metadata, and build reports that group payments by those fields. It works, but you own the code, the edge cases (renewals, refunds, currencies) and the reporting.
  2. Fire a purchase event from the browser. Quick to add to a thank-you page, but it misses buyers who close the tab or block scripts, and anyone can send a fake one. Treat it as a fallback, not a source of truth.
  3. Use an analytics tool that reads Stripe directly. The tool receives Stripe’s webhooks and matches each payment to the visitor who made it. This is the approach theBizness.ai takes.

Setting it up with theBizness.ai

1. Install the tracking script

Add the script to every page of your site. It records each visit’s referrer and UTM tags and keeps a first-party visitor ID on your domain. The installation guide has instructions for plain HTML, Next.js, React, Vue, WordPress, Django and Laravel.

2. Connect Stripe with a restricted key

On the Setup page, follow the link that opens Stripe with the right permissions already selected, create a restricted key and paste it in. Never use your secret key. The key is encrypted before it is stored. theBizness.ai then creates one webhook endpoint in your Stripe account for new sales (including delayed methods such as ACH and SEPA once the money arrives), renewals, refunds and subscription changes.

3. Pass the visitor into Checkout

When your server creates a Checkout Session, add your website ID and the visitor and session IDs that the script stores in two first-party cookies. That is what ties the payment to the visit:

const session = await stripe.checkout.sessions.create({
  mode: "payment",
  line_items: [{ price: priceId, quantity: 1 }],
  success_url: "https://yourdomain.com/thank-you",
  metadata: {
    websiteId: process.env.THEBIZNESS_WEBSITE_ID,
    visitorId: cookies.get("thebizness_visitor_id"),
    sessionId: cookies.get("thebizness_session_id"),
  },
});

For subscriptions and free trials, set the same values in subscription_data.metadata as well, because the Checkout Session’s metadata does not carry over to later renewal charges. Without the visitor IDs, the sale is still recorded, but it cannot be linked to a traffic source.

What you get

  • Every sale is credited to the source of the buyer’s most recent visit with a referrer or UTM tag in the 30 days before the purchase. A return from Stripe Checkout does not replace that source.
  • Renewals are credited to the source of the customer’s earliest attributed purchase.
  • Refunds are recorded, and subscription cancellations appear on the Cancellations page.
  • Payments made with Stripe test keys are stored but kept out of your analytics.
  • Totals are kept per currency. Your reporting currency is the headline and other currencies are listed beside it; nothing is converted.
  • Revenue, orders, conversion rate and revenue per visitor by source, medium and campaign, plus each customer’s total spent and path to purchase.

Avoid counting a sale twice

Use one reporting method per processor. If Stripe is connected, do not also forward the same payments from your own webhook or thank-you page with a different order ID. A browser or server report that uses the Checkout Session ID (cs_…) or PaymentIntent ID (pi_…) as its order ID is replaced by Stripe’s own record, but your own order number cannot be matched and would be counted again.

Not on Stripe? The same attribution works for any processor if your server reports each sale to our conversions API with your ingest secret. The revenue attribution docs cover both paths in full, and Whop sellers can connect directly; see tracking Whop sales by traffic source.

See which channels bring paying customers

theBizness.ai connects your traffic to Stripe and Whop revenue, so you can put your budget where it earns.

Start 14-day free trial

14-day free trial. No card required.