Stripe IntegrationStripe Checkout, Billing & Webhooks

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.

Imtiaz Rayhan
Imtiaz RayhanCo-Founder & Lead Engineer, DotCamp & TrimStats
Tested against Stripe & live TrimStats APIs
Seeded demo workspace
TrimStats Revenue dashboard showing $32,753 attributed revenue, 559 orders, $58.59 AOV, and top revenue-generating referrers and landing pagesTrimStats Revenue dashboard showing $32,753 attributed revenue, 559 orders, $58.59 AOV, and top revenue-generating referrers and landing pages
Inspect Net Revenue, Orders, Paying Customers, AOV, Revenue per Visitor, and Conversion Rate segmented by Referrer, UTM campaign, Landing Page, and Country.
Direct answer

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. 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.tsxts
    1const attribution = window.trimstats?.attribution?.() ?? {};
    2
    3const 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. 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.tsts
    1import Stripe from 'stripe';
    2
    3const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
    4
    5export async function POST(req: Request) {
    6 const { priceId, userId, attribution } = await req.json();
    7 const trimstatsMeta = JSON.stringify(attribution ?? {});
    8
    9 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 });
    18
    19 return Response.json({ url: session.url });
    20}
  3. 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. 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.

Recommended taxonomy

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 nameWhen to fireSample properties
pricing_viewedVisitor lands on or scrolls to your SaaS pricing tiers.{"billing":"monthly"}
billing_interval_toggledProspect switches between monthly and annual Stripe prices.{"interval":"annual"}
checkout_startedUser clicks Subscribe and triggers stripe.checkout.sessions.create().{"plan":"growth","currency":"USD"}
checkout_canceledBuyer returns via cancel_url without completing payment.{"plan":"growth"}
billing_portal_openedExisting customer opens the Stripe Customer Portal to manage plans.{"source":"billing_settings"}
Seeded demo workspace
TrimStats verified Stripe webhook settings paired with a chronological visitor timeline joining a Hacker News entry to a $290 Stripe subscriptionTrimStats verified Stripe webhook settings paired with a chronological visitor timeline joining a Hacker News entry to a $290 Stripe subscription
Verified Stripe webhook events appear inline inside each customer timeline with full transaction deduplication on external_tx_id.

End-to-end SaaS funnel closing on verified Stripe webhook payments

30-day seeded acme.dev demo dataset across 5 acquisition-to-payment steps

visitors
  1. 1Landing page visit
    12,480 visitors100.0%
  2. 2Viewed /pricing
    3,420 visitors27.4%-72.6% drop
  3. 3Completed signup
    612 visitors4.9%-82.1% drop
  4. 4Started Stripe Checkout
    384 visitors3.1%-37.3% drop
  5. 5Stripe payment webhook
    264 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.

Source: TrimStats seeded demo workspace (acme.dev)
View chart data table
LabelVisitors
Landing page visit12,480 visitors
Viewed /pricing3,420 visitors
Completed signup612 visitors
Started Stripe Checkout384 visitors
Stripe payment webhook264 visitors

Stripe analytics FAQ

Implementation details, privacy trade-offs, and event-quota answers.

Which Stripe webhook events does TrimStats process?
TrimStats processes checkout.session.completed (as one_time or subscription_new), invoice.paid (classified as subscription_renewal when billing_reason equals subscription_cycle), and charge.refunded (subtracting amount_refunded via refund:<charge_id>). Any other Stripe event returns 200 OK with ignored: true.
How does TrimStats verify that incoming Stripe webhooks are authentic?
The Fastify collector verifies the raw HTTP request bytes against the stripe-signature HMAC-SHA256 header using your encrypted whsec_ signing secret with a 5-minute timestamp replay tolerance before writing any row to ClickHouse.
Will Stripe renewals continue attributing to the original marketing channel?
Yes. Passing trimstats inside subscription_data.metadata preserves the original vid, uid, referrer, landing page, and UTM snapshot on every recurring invoice.paid webhook, and ClickHouse also joins against historical visitor journeys.
How does TrimStats handle non-USD Stripe currencies such as EUR, GBP, or JPY?
TrimStats stores each Stripe charge in its original currency and minor units alongside normalized usd_cents across 13 built-in FX currencies (USD, EUR, GBP, CAD, AUD, CHF, JPY, INR, BDT, BRL, SGD, SEK, and NZD), handling zero-decimal currencies like JPY automatically.
Does Stripe revenue attribution work if my marketing site stays cookie-less?
Yes. Even in default cookie-less mode, window.trimstats.attribution() captures the landing page, referrer, and UTM tags for the session and embeds them in checkout metadata. Turning on first-party ID mode or calling identify() extends lookup to 90 days.
Are Stripe webhook deliveries deduplicated if Stripe retries a failed request?
Yes. TrimStats keys every ingested Stripe checkout session, recurring invoice, and charge refund by external_tx_id in ClickHouse, so automatic Stripe webhook retries never double-count orders or inflate attributed net revenue.
Imtiaz Rayhan
Integration guide verified by
Imtiaz Rayhan (Co-Founder & Lead Engineer, DotCamp & TrimStats)

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.

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.

Verified against live TrimStats APIs and tracker bundle.