Integrations

Revenue

Connect Stripe, Polar or Creem to see which sources, campaigns, pages and AI assistants bring paying customers.

Connect your payment provider and every payment is matched to the visit it came from: the source, campaign, landing page, country and device, and whether an AI assistant sent the visitor or an AI agent checked out for them. The match is always by an exact id, never by guessing from IP addresses or times. Nothing is stored in the browser, so it needs no cookie banner.

The Revenue page shows revenue, payments, customers, revenue per visitor and the share of visitors who paid, then where paying customers came from.

1. Connect your payments

In your website's Settings › Integrations, pick a provider and paste a key. AgentStats checks the key, adds one webhook to your account with it and keeps the key encrypted. You don't set up a webhook yourself. Payments are recorded from the moment you connect.

ProviderKeyWhat it needs
StripeA restricted key (rk_live_…): Developers › API keys › Create restricted keyWebhook Endpoints: Write. Add Account: Read to show the account's name. Nothing else.
PolarContinue with Polar and pick the organization, or paste an organization access token (polar_oat_…): Settings › Access TokensSigning in asks for exactly what's needed. A token needs organizations:read and webhooks:write. Sandbox organizations work too.
CreemAn API key (creem_…): Developers › API keyswebhooks:write. Test keys (creem_test_…) work too.

None of these keys can move money. Disconnecting removes the webhook; payments recorded so far stay.

Test-mode payments (Stripe test keys, Polar's sandbox, Creem's test mode) show on the Revenue page until your first live payment, then they're left out.

Use whichever fits how you take payments. They work together, and a payment that comes in twice is only counted once.

The script (v1.js, lite.js or the npm SDK) adds the page load's id to links to Stripe Payment Links (buy.stripe.com), Polar checkout links and Creem payment links when they're clicked, and to Stripe's <stripe-pricing-table> and <stripe-buy-button>. A link that already sets its own client_reference_id, reference_id or metadata[agentstats_ref] is left alone. Turn it off with checkoutLinks: false (data-checkout-links="false").

Checkouts you create on your server

Read the page load's id in the browser with AgentStats.attributionId(), send it with the request that starts checkout, and put it on the checkout as agentstats_ref:

// Browser
const ref = AgentStats.attributionId()

// Server
await stripe.checkout.sessions.create({
  // …line items, mode, success_url
  client_reference_id: ref,
  metadata: { agentstats_ref: ref },
  subscription_data: { metadata: { agentstats_ref: ref } }, // subscriptions
})

For a Stripe PaymentIntent you create yourself, put it in the intent's metadata.agentstats_ref.

Signups: payments days later

Most people who pay a subscription signed up first, often on another day. Call identify() when someone signs up or logs in, with your user id and, if you like, their email:

AgentStats.identify(user.id, { email: user.email })

A payment that names them later is matched to the visit they signed up on, even on another device: the buyer's email at checkout, Polar's customer external_id, or metadata.agentstats_uid on the checkout. AgentStats keeps only a keyed hash of the id and email, never the values.

Success URL: no code

Send buyers back to your site after they pay, with the checkout's id in the address. The page they land on names their visit:

  • Stripe: https://yoursite.com/thanks?session_id={CHECKOUT_SESSION_ID}
  • Polar and Creem: https://yoursite.com/thanks?checkout_id={CHECKOUT_ID}

How amounts are counted

  • Amounts are after discounts and before tax, net of refunds.
  • Renewals and later purchases keep the source of the customer's first matched payment.
  • The page shows the currency most of the period's revenue came in. Payments in other currencies are listed beside it, never converted.
  • A payment with no id to match is still counted in revenue, under Not matched in How payments were matched. If the buyer's return page or the subscription's checkout arrives afterwards, it's matched then.