Popular7 min read

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.

Imtiaz Rayhan
Imtiaz RayhanCo-Founder & Lead Engineer, DotCamp & TrimStats
Verified against live TrimStats APIs
Quick reference

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 modelGets credit in Alex exampleBest question it answers
First-touchnews.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.
Site analytics / Revenue Attribution
Notice the bottom row (perplexity.ai first-touch vs (direct) last-touch): toggling between First-touch and Last-touch lets you see both discovery ROI and closing channels.
Why Revenue per Visitor (RPV) beats raw conversion rate

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.

Site settings / Revenue Attribution Webhooks
Copy your site-specific webhook URL from Site settings, register it in Stripe, Paddle, or Polar, and save the signing secret so every payment is cryptographically verified.
  1. 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.tsts
    1const attribution = window.trimstats?.attribution?.() ?? {};
    2
    3await fetch('/api/checkout', {
    4 method: 'POST',
    5 headers: { 'content-type': 'application/json' },
    6 body: JSON.stringify({ priceId: 'price_pro_monthly', attribution }),
    7});
  2. 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 as vid, uid, ref, lp, utm_source, utm_campaign).

  3. 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, and utm_campaign fields 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 by external_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.

Common technical questions

Can I switch between first-touch and last-touch attribution after webhooks are ingested?
Yes. Because TrimStats joins payment rows against ClickHouse journey history dynamically at query time, you can toggle between first_touch and last_touch attribution instantly without replaying historical webhooks.
Which currencies does TrimStats normalize automatically into USD?
TrimStats preserves original transaction currencies and normalizes 13 built-in currencies (USD, EUR, GBP, CAD, AUD, CHF, JPY, INR, BDT, BRL, SGD, SEK, and NZD) into usd_cents, handling zero-decimal currencies like JPY cleanly.

Related guides