Attribute every Stripe payment, renewal, and refund to its source.
Forward one lightweight attribution snapshot into Stripe Checkout metadata and verify signed Stripe webhooks server-side so ad blockers never hide revenue.


How does TrimStats connect Stripe payments to marketing referrers and landing pages?
TrimStats connects to Stripe via cryptographically verified server webhooks for checkout.session.completed, invoice.paid, and charge.refunded. Pass window.trimstats.attribution() into Stripe checkout and subscription metadata, and TrimStats joins every payment, renewal, and refund to the buyer's 90-day ClickHouse journey across 13 currencies with zero client-side thank-you pixels.
Step-by-step setup for Stripe
Copy-paste implementation verified against the live TrimStats tracker and collector APIs.
- 1
Read the browser attribution snapshot before checkout
In your client-side upgrade button handler, call window.trimstats?.attribution?.() and include the returned object in your POST body when creating a Stripe Checkout Session.
components/UpgradeButton.tsxts1const attribution = window.trimstats?.attribution?.() ?? {};23const res = await fetch('/api/checkout', {4 method: 'POST',5 headers: { 'content-type': 'application/json' },6 body: JSON.stringify({ priceId: 'price_growth_monthly', attribution }),7});8const { url } = await res.json();9window.location.assign(url); - 2
Attach metadata.trimstats to Stripe Checkout and subscription data
Serialize the attribution object inside both metadata.trimstats and subscription_data.metadata.trimstats so recurring invoice.paid renewals inherit the original acquisition source.
app/api/checkout/route.tsts1import Stripe from 'stripe';23const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);45export async function POST(req: Request) {6 const { priceId, userId, attribution } = await req.json();7 const trimstatsMeta = JSON.stringify(attribution ?? {});89 const session = await stripe.checkout.sessions.create({10 mode: 'subscription',11 line_items: [{ price: priceId, quantity: 1 }],12 client_reference_id: userId,13 metadata: { trimstats: trimstatsMeta },14 subscription_data: { metadata: { trimstats: trimstatsMeta } },15 success_url: 'https://acme.dev/dashboard?upgraded=1',16 cancel_url: 'https://acme.dev/pricing',17 });1819 return Response.json({ url: session.url });20} - 3
Register your site webhook URL in Stripe Dashboard
Under Stripe Developers -> Webhooks -> Add endpoint, enter your TrimStats endpoint URL (https://collect.trimstats.com/v1/webhooks/stripe/{siteId}) and subscribe to checkout.session.completed, invoice.paid, and charge.refunded.
- 4
Save the whsec_ signing secret in TrimStats Site settings
Paste Stripe signing secret into Site settings -> Revenue Attribution Webhooks. TrimStats encrypts the secret at rest in PostgreSQL and verifies stripe-signature HMAC-SHA256 headers on raw bytes with a 5-minute replay window.
High-signal custom events to track for Stripe
Fire any event with window.trimstats?.('event', name, props) and attach it to conversion goals or multi-step ClickHouse funnels.
| Event name | When to fire | Sample properties |
|---|---|---|
| pricing_viewed | Visitor lands on or scrolls to your SaaS pricing tiers. | {"billing":"monthly"} |
| billing_interval_toggled | Prospect switches between monthly and annual Stripe prices. | {"interval":"annual"} |
| checkout_started | User clicks Subscribe and triggers stripe.checkout.sessions.create(). | {"plan":"growth","currency":"USD"} |
| checkout_canceled | Buyer returns via cancel_url without completing payment. | {"plan":"growth"} |
| billing_portal_opened | Existing customer opens the Stripe Customer Portal to manage plans. | {"source":"billing_settings"} |


End-to-end SaaS funnel closing on verified Stripe webhook payments
30-day seeded acme.dev demo dataset across 5 acquisition-to-payment steps
- 1Landing page visit12,480 visitors100.0%
- 2Viewed /pricing3,420 visitors27.4%-72.6% drop
- 3Completed signup612 visitors4.9%-82.1% drop
- 4Started Stripe Checkout384 visitors3.1%-37.3% drop
- 5Stripe payment webhook264 visitors2.1%-31.3% drop
Measuring Stripe webhook settlement as the final step exposes exact checkout abandonment (31.3% drop from checkout start to paid).
Methodology: Seeded 30-day acme.dev demo funnel connecting browser events with server-verified Stripe webhook completions.
View chart data table
| Label | Visitors |
|---|---|
| Landing page visit | 12,480 visitors |
| Viewed /pricing | 3,420 visitors |
| Completed signup | 612 visitors |
| Started Stripe Checkout | 384 visitors |
| Stripe payment webhook | 264 visitors |
Stripe analytics FAQ
Implementation details, privacy trade-offs, and event-quota answers.
Which Stripe webhook events does TrimStats process?
How does TrimStats verify that incoming Stripe webhooks are authentic?
Will Stripe renewals continue attributing to the original marketing channel?
How does TrimStats handle non-USD Stripe currencies such as EUR, GBP, or JPY?
Does Stripe revenue attribution work if my marketing site stays cookie-less?
Are Stripe webhook deliveries deduplicated if Stripe retries a failed request?
Co-founder of DotCamp LLC in Brooklyn, NY and lead engineer of TrimStats. Ships privacy-first web analytics, ClickHouse pipelines, and WordPress plugins used on 115,000+ active sites.
- • Architect of the TrimStats 1.96 KB gzipped browser tracker, Fastify collector, and ClickHouse MergeTree pipeline
- • Co-founder of DotCamp LLC (est. 2019), creator of Ultimate Blocks (50,000+ installs), WP Table Builder (50,000+ installs), Tableberg, and OptimizeCamp
- • WordPress.org plugin & theme developer since 2016 with 1,200+ community support replies and 5M+ cumulative plugin downloads
Verification standard: Code snippets, custom event payloads, and webhook contracts for Stripe are verified against the live TrimStats tracker (1.96 KB gzipped) and collector schema as of 2026-11-30.
Related documentation and guides
Instrument Stripe in under 60 seconds
Start on Starter ($17/month for 100,000 monthly events), with cookie-less privacy defaults and full access to revenue webhooks, funnels, cohorts, and UI friction.