Revenue

Stripe

One webhook endpoint per website, two metadata keys on each checkout, and every Stripe payment lands on the visit that caused it.

Updated All docs as one Markdown file

The webhook

In Stripe, add an endpoint for this URL, which is on the Connect payments step of the website in the dashboard with the id filled in:

Endpoint URL
https://geckostats.com/api/webhooks/stripe/<website-id>

Send it checkout.session.completed, checkout.session.async_payment_succeeded, invoice.paid and charge.refunded. Paste the endpoint's signing secret into the same step; every event is verified against it. Subscription renewals arrive as invoice.paid and are counted as renewals; refunds subtract themselves, and a second partial refund replaces the first.

Metadata on the checkout

Put ml_visitor_id and ml_session_id from window.geckostats.attribution() into the Checkout Session's metadata, and make success_url a page on your site ending in ?session_id={CHECKOUT_SESSION_ID}. The general shape is on the attribution page; the Stripe-specific part is only those two names.

Node
await stripe.checkout.sessions.create({ mode: 'subscription', line_items, metadata: { ...existingMetadata, ...attribution }, success_url: 'https://<your-domain>/thanks?session_id={CHECKOUT_SESSION_ID}', cancel_url: 'https://<your-domain>/pricing', });

Stripe Payment Links (buy.stripe.com) need no change: the script sets client_reference_id to ml_<visitor>__<session> when the link is clicked, unless your code already sets its own.

Several websites on one Stripe account

Stripe sends every event to every endpoint it has, so two websites on one account each receive each payment. A payment is placed by, in order: an ml_site_id key in its metadata if you set one; the website the visitor was actually seen on; for a renewal, which carries no visitor, the website this Stripe customer paid before. A payment that none of those place on a website is not recorded there. A single website is unaffected.

Test mode

A test-mode endpoint with a test-mode signing secret works the same way, and test payments arrive through the same handler, so the whole path can be checked before a real card is involved.