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
- 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.
- 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). - 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 - 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’smetadata. For subscriptions, put it insubscription_data.metadatatoo, 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.
CrispStats on Stripe
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.
- On a Payment Link there is no metadata per visitor: add the id to the link’s URL as
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
- Revenue attribution: which traffic pays
See which source, page and campaign each payment came from.
- First touch vs last touch attribution
First touch, last touch and multi-touch attribution in plain terms, with a worked example and how to join a payment to the visit that caused it.
- Revenue per visitor calculator
Enter visitors, conversion rate and average order value to get revenue per visitor, monthly revenue, and what a 10% improvement is worth.
- Web analytics for SaaS products
See which channels bring paying customers, where trials stall in the funnel, and how your app performs for real users, from one cookieless script.
Guides
- 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 best SaaS analytics tools, layer by layer: website, product and revenue
Twelve SaaS analytics tools sorted into the three layers a SaaS needs, with prices, limits, a worked stack and the method behind the list.
- The best marketing and revenue attribution tools for SaaS and indie makers
Twelve marketing attribution tools that tie payments to traffic sources, compared by payment providers read, price and limits.
Other integrations
Payment providers
Frameworks
Site builders
Ecommerce platforms
Tag managers
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.