Skip to content

Payment providers

Stripe revenue attribution with CrispStats

To see which traffic sources pay, connect Stripe in CrispStats with a restricted key, then put the visitor id in the Checkout Session metadata as crispstats_visitor_id. One-time payments, subscriptions, renewals and refunds then appear on the Revenue screen, each credited to the visit that led to it.

Updated

Set up CrispStats on Stripe

  1. 01

    Step 1: Open the Stripe panel

    The CrispStats script must already run on your site. Open the site’s Settings, select Integrations, choose Connect a payment provider and pick Stripe. You need permission to manage the site’s settings.

  2. 02

    Step 2: Create a restricted key in Stripe

    Select Create a restricted key in Stripe. It opens Stripe’s restricted key form with six permissions filled in, and only Webhook Endpoints: Write can change anything; the rest are read-only and serve the product names and the history import. Leave every other resource at None, create the key and copy it. It starts with rk_live_ (rk_test_ in a sandbox).

  3. 03

    Step 3: Paste the key and connect

    Paste the key and select Connect Stripe. CrispStats creates a webhook endpoint for this site with the five events below, saves its signing secret and the key encrypted, and starts importing the payments made before today. Each payment is read back from Stripe’s API with your key before it counts as verified revenue. A full secret key (sk_live_) is refused.

    checkout.session.completedcheckout.session.async_payment_succeededinvoice.paidpayment_intent.succeededcharge.refunded
  4. 04

    Step 4: Pass the visitor id at checkout

    Call crispstats.id() in the browser before you send the visitor to checkout, and put the id in the Checkout Session’s metadata. For subscriptions, put it in subscription_data.metadata too, so renewals are attributed. Get the id in a click handler, not on your server: the id belongs to the browser that asks.

    checkout.js
    // In the browser, before you send the visitor to checkoutconst visitorId = await crispstats.id();// On your server, when you create the Checkout Sessionconst session = await stripe.checkout.sessions.create({// ...your line items and URLsmetadata: { crispstats_visitor_id: visitorId },// Subscriptions only: renewals carry the subscription's metadatasubscription_data: { metadata: { crispstats_visitor_id: visitorId } },});

Check that it works

The Stripe row in Settings, Integrations shows Connected, whether it is live, and when it last updated. Make a purchase from a page with the script: it appears under Payments on the Revenue screen with the source of that visit. If the key stops working or loses a permission, the row says so and names the way out.

Payments through Stripe on the demo site, Quillbook, on generated traffic. Prices are the demo company's. Open it in the demo 
  • What you get

    • Revenue by source, channel, campaign and landing page, credited to the first touch known for the visitor.
    • New subscriptions and renewals kept apart, one-time payments on their own, and MRR on the Revenue screen.
    • Refunds recorded as negative payments; Stripe reports the total refunded so far, and only the difference is stored.
    • Product names from each Checkout Session’s line items, and past payments imported when you connect with a key.
    • Customer email stored only hashed and masked; renewals without a visitor id take the attribution of the customer’s earliest attributed payment.
  • Notes and limits

    • On a Payment Link there is no metadata per visitor: add the id to the link’s URL as client_reference_id. Values that are not 32 hexadecimal characters are ignored, so your own order ids there never become visitor ids.
    • Payments taken with a Payment Intent and no Checkout are recorded only when the Payment Intent carries the visitor id in its own metadata.
    • Stripe sends each payment within seconds. CrispStats also asks Stripe for recent events every 15 minutes, so a payment the webhook missed still arrives, and a payment seen both ways is stored once.
    • A test key connects in test mode once you choose Connect in test mode. Test payments show with a Test tag on the Revenue screen and are kept out of revenue, MRR and every total.
    • A payment without a visitor id is still recorded and counted in revenue, MRR and every total. It is left out of the source, campaign and channel breakdowns rather than filed under Direct.
    • Connections made earlier with a webhook you added by hand keep working, but cannot import history or verify payments. Connect again with a key to add both.
    • If RevenueCat bills through the same Stripe account and is also connected, connect only one of the two, or each payment counts twice.
    • CrispStats does not calculate churn or expansion. For those, and for invoices and disputes, Stripe stays the source of truth.

The docs page covers the optional steps this guide leaves out.

Setup questions. Straight answers.

What people ask before they connect it.

  • So CrispStats can create the webhook endpoint for you, and delete it when you disconnect. Every other permission on the key is read-only, and a full secret key is refused.

  • Yes, when the visitor id is also in subscription_data.metadata. Each renewal invoice then carries the id and is credited to the same first touch as the first payment.

  • They are recorded and counted in revenue, MRR and every total, and left out of the source and campaign breakdowns. A renewal or refund without an id takes the attribution of the same customer's earliest attributed payment.

  • Yes. Connecting with a restricted key starts the import at once. It reads past Checkout payments, subscription invoices and refunds, from your first payment, on every plan. Most of them have no visit to tie to, so they count in revenue and MRR but stay out of the source breakdowns.

  • Yes, history import included. Every feature is on every plan and in the 14-day free trial, and payments are kept on every plan, while other traffic data is kept for the plan's period, 24 months on Starter.

Not answered here? Write to hello@crispstats.com

Go further

Related

Guides

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.