Revenue Attribution Overview
Connect payment provider webhooks directly to TrimStats to attribute one-time orders, subscriptions, renewals, and refunds to referrers, UTM campaigns, and landing pages.
How does TrimStats server-side payment-webhook revenue attribution work?
Attach window.trimstats.attribution() to checkout metadata and register your Stripe, Paddle, Polar, or Custom HMAC webhook secret in Site settings. TrimStats verifies raw-body signatures on the collector, deduplicates transactions by external_tx_id, normalizes 13 currencies into USD, and joins payments to 90-day ClickHouse visitor journeys.
What is revenue attribution? First-touch vs Last-touch
Most buyers do not pay on their very first visit. Revenue attribution connects a completed payment back to the marketing channel, campaign, or landing page that originally brought that customer in.
Consider a typical SaaS purchase: on Day 1, Alex discovers your benchmark post via Hacker News (news.ycombinator.com). On Day 6, Alex searches your brand on Google to check pricing. On Day 9, Alex types your URL directly ((direct)) and subscribes for $290. Who deserves credit?
| Attribution model | Gets credit in Alex example | Best question it answers |
|---|---|---|
| First-touch | news.ycombinator.com + /blog/script-benchmark | "Which channels and content bring us net-new paying customers?" Best for evaluating SEO, content marketing, and top-of-funnel spend. |
| Last-touch | (direct) (or final non-direct referrer google.com) | "Which touchpoint closed the deal right before checkout?" Best for evaluating retargeting, lifecycle emails, and bottom-of-funnel offers. |
perplexity.ai first-touch vs (direct) last-touch): toggling between First-touch and Last-touch lets you see both discovery ROI and closing channels.A channel converting 3% of visitors onto a $17 Starter plan generates $0.51 per visitor, while a channel converting 1% onto a $290 annual plan generates $2.90 per visitor. Always compare Revenue / Visitor (RPV) alongside conversion rate.
How server-verified revenue attribution works
Client-side thank-you-page revenue scripts break on ad blockers, failed redirects, subscription renewals, and refunds. TrimStats instead receives cryptographically signed server-to-server webhooks directly from Stripe, Paddle, Polar, or your own backend, then joins each payment to the visitor historical journey in ClickHouse.
- 1
Capture the browser attribution snapshot at checkout
Before redirecting a customer to checkout, read
window.trimstats?.attribution?.()and forward that object to your backend when creating the checkout session.checkout-client.tsts1const attribution = window.trimstats?.attribution?.() ?? {};23await fetch('/api/checkout', {4 method: 'POST',5 headers: { 'content-type': 'application/json' },6 body: JSON.stringify({ priceId: 'price_pro_monthly', attribution }),7}); - 2
Attach attribution to checkout metadata
Store the snapshot inside your payment provider metadata under a JSON string key named
trimstats(or pass flat keys such asvid,uid,ref,lp,utm_source,utm_campaign). - 3
Register your webhook endpoint & signing secret
Copy your site-specific webhook URL from Site settings -> Revenue Attribution Webhooks (
https://collect.trimstats.com/v1/webhooks/{provider}/{siteId}), register it with your payment provider, and paste the signing secret into TrimStats (encrypted at rest in PostgreSQL).
90-day ClickHouse lookup & attribution models
When a signed webhook arrives, the collector computes the visitor hash from vid (fp:{siteId}:{vid}) or uid (uid:{siteId}:{uid}) and queries ClickHouse for that visitor pageviews across the past 90 days.
- First-touch attribution (`first_touch`): Credits the earliest recorded referrer, UTM source, UTM campaign, and landing page within the 90-day lookback window.
- Last-touch attribution (`last_touch`): Credits the most recent referrer, UTM source, and UTM campaign prior to purchase.
- Graceful metadata fallback: Even if a visitor was in cookie-less mode or cleared browser storage before purchasing, TrimStats falls back to the
ref,lp,utm_source, andutm_campaignfields embedded in the webhook metadata. - Subscription renewals & refunds: New subscriptions (
subscription_new), renewals (subscription_renewal), one-time payments (one_time), and negative refunds (refund) are all tracked cleanly and deduplicated byexternal_tx_id.
Multi-currency normalization & Revenue KPIs
TrimStats stores each transaction original currency and minor-unit amount alongside a normalized usd_cents amount so multi-currency totals aggregate cleanly. Built-in FX normalization supports USD, EUR, GBP, CAD, AUD, CHF, JPY, INR, BDT, BRL, SGD, SEK, and NZD (handling zero-decimal currencies like JPY automatically).
Your site Revenue dashboard displays Net Revenue, Orders, Paying Customers, Average Order Value (AOV), Revenue per Visitor (RPV), and Visitor-to-Customer Conversion Rate, broken down by Referrer, UTM Source, UTM Campaign, Landing Page, and Country.
Stripe Webhooks
Verify stripe-signature headers for checkout sessions, invoices, and refunds.
Paddle Webhooks
Verify paddle-signature headers and attach custom_data on Paddle Billing.
Polar Webhooks
Standard Webhooks verification for order.paid and order.refunded.
Custom HMAC Webhooks
Send orders from Shopify, Lemon Squeezy, PayPal, or your own billing engine.
Common technical questions
Can I switch between first-touch and last-touch attribution after webhooks are ingested?
Which currencies does TrimStats normalize automatically into USD?
Related guides
Step-by-step guide to forwarding Stripe checkout sessions, subscription invoices, and refunds to TrimStats with HMAC verification.
Connect Paddle Billing webhooks and custom_data attribution to track SaaS subscriptions and one-time payments in TrimStats.
Attribute Polar.sh orders, subscription renewals, and refunds using Standard Webhooks signature verification.
Send revenue events from any payment processor, e-commerce store, or internal billing service using a simple HMAC-SHA256 signed JSON webhook.