Polar Revenue Webhook
Attribute Polar.sh orders, subscription renewals, and refunds using Standard Webhooks signature verification.
How do you connect Polar.sh webhooks to TrimStats revenue attribution?
Include window.trimstats.attribution() in Polar checkout metadata (as metadata.trimstats JSON or flat keys), register /v1/webhooks/polar/{siteId} in Polar for order.paid and order.refunded, and save your Standard Webhooks signing secret in TrimStats Site settings.
Attach attribution to Polar checkout metadata
When creating a Polar checkout session on your server, pass the browser attribution snapshot inside metadata.trimstats (or flat string metadata keys vid, uid, ref, lp, utm_source, utm_campaign).
1import { Polar } from '@polar-sh/sdk';23const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN! });45export async function POST(req: Request) {6 const { productId, userId, attribution } = await req.json();78 const checkout = await polar.checkouts.create({9 products: [productId],10 metadata: {11 trimstats: JSON.stringify({12 ...(attribution ?? {}),13 uid: userId ?? attribution?.uid ?? '',14 }),15 },16 successUrl: 'https://acme.com/thank-you',17 });1819 return Response.json({ url: checkout.url });20}Configure Polar Standard Webhooks
polar_whs_... or whsec_... secret, and save.- 1
Add a Webhook endpoint in Polar
In your Polar organization settings under Webhooks -> Add Endpoint, set the URL to
https://collect.trimstats.com/v1/webhooks/polar/{siteId}and enable `order.paid` and `order.refunded`. - 2
Save the signing secret in TrimStats
Copy the secret (
polar_whs_...orwhsec_...) from Polar and save it under Site settings -> Revenue Attribution Webhooks with provider set to Polar.
TrimStats validates the webhook-id, webhook-timestamp, and webhook-signature (v1,<base64>) headers over ${webhookId}.${webhookTimestamp}.${rawBody} using timing-safe comparison and a 5-minute replay tolerance.
Common technical questions
Which Polar webhook signature standard does TrimStats verify?
Can I send flat metadata keys to Polar instead of a serialized JSON string?
Related guides
Connect payment provider webhooks directly to TrimStats to attribute one-time orders, subscriptions, renewals, and refunds to referrers, UTM campaigns, and landing pages.
Step-by-step guide to forwarding Stripe checkout sessions, subscription invoices, and refunds to TrimStats with HMAC verification.
Send revenue events from any payment processor, e-commerce store, or internal billing service using a simple HMAC-SHA256 signed JSON webhook.