Revenue

How a payment finds its visit

Every payment is joined to the visit that produced it, which is how a sale ends up next to the tweet, the article or the search query that brought it. This page is what has to be true for that to work.

Updated All docs as one Markdown file

The identity

By default the script stores nothing on the visitor's device. The collector works out a visitor id from a daily-rotating salted hash, hands it back, and the script keeps it in memory for the page. It is exposed as:

JavaScript
window.geckostats.attribution() // { ml_visitor_id: "…", ml_session_id: "…" }

A payment that carries those two values as metadata is attributed to that visit the moment the provider's webhook arrives. Nothing else is needed.

Getting it onto the checkout

Where the checkout is created on your server, the identity is not in the request: there is no cookie to read. The browser has to send it, and the server merges it into the metadata it already sets, keeping every existing key.

Server-side checkout
// client fetch('/api/checkout', { method: 'POST', body: JSON.stringify({ plan, attribution: window.geckostats?.attribution?.() }), }); // server const session = await stripe.checkout.sessions.create({ // … metadata: { ...existingMetadata, ...body.attribution }, success_url: 'https://<your-domain>/thanks?session_id={CHECKOUT_SESSION_ID}', });

Where the checkout is created in the browser, spread the same object into its metadata.

A static payment link in an anchor needs nothing: the script tags it on click. Dodo Payments links get the two values as metadata_ query parameters, Stripe payment links get them in client_reference_id and Polar checkout links in reference_id, in the form ml_<visitor>__<session>. If your code already sets one of those, yours is kept.

A redirect to a payment link from JavaScript is the one case the click tagging cannot see. Append the values yourself, in the same form.

The success page

Every checkout should return to a page on your site that loads the script. The provider appends its own id to that URL, and that id is how a payment whose metadata was lost is still recovered. Keep the query parameters on the page until it has loaded.

ProviderSuccess URL on your siteWhat the provider appends
Stripeend it with ?session_id={CHECKOUT_SESSION_ID}Stripe fills in the session id
Polarend it with ?checkout_id={CHECKOUT_ID}Polar fills in the checkout id
Creemany page?checkout_id=…&order_id=…
Dodo Paymentsreturn_url, or ?redirect_url=… on a payment link?payment_id=… or ?subscription_id=…

When the metadata is missing

The payment is not dropped. It is matched by the provider's own id from the success page, then by the customer's email against anyone the site has identified, and if nothing matches yet it is held and matched when the identity catches up. The settings of each website list every payment still waiting, which is the place to look when a sale seems to be missing.

Attribution is last touch by default, first touch if you prefer, per website. Neither is correct, so the choice is yours and the dashboard says which produced each figure. Traffic from your own other domains, such as docs or the app, is not counted as a referral once you list them in the website's settings.