A hosted checkout breaks conversion attribution because the ad click lives in a browser on your landing page, while the confirmed purchase arrives later from the payment provider as a webhook. The payment is real, but the webhook has no cookie jar, no landing URL and no click parameters. Without a shared reference, your server can’t tell which browser record belongs to that order.

The fix is a first-party attribution index. Capture the click IDs and session context before the visitor leaves, save them under a short random ID, and pass only that ID into the checkout. When the paid webhook arrives, read the same ID back and load the original row. The index ID is the join. It isn’t another ad-platform click ID.

Why the join key must be opaque

I learned how fragile the alternative is on a Brazilian client’s deposit funnel in September 2026. Its server stored browser context per user keyed on the email from the site’s data layer, and the payment webhook read it back by the same email. When the site started pushing a SHA-256 hash of the email instead, new rows were written under the hash while the webhook kept looking up the plain address. Every lookup came back empty, and GA4 purchase coverage fell from 97% to 67%, then 26%, then 18% over three days. Meanwhile the bank side stayed normal, the server’s outbound requests kept returning 200, and the pixels kept firing.

A random ID that both sides carry unchanged doesn’t have that failure mode. Email and phone belong in the payload, not in the key.

What the flow has to preserve

Keep the information that can reconnect the paid order with its ad session, and keep the checkout’s share of it small. The row usually holds the platform click IDs, readable campaign parameters, first-party browser identifiers, the consent state and where it came from, and timestamps. The checkout carries one random reference.

Keep the order ID beside the index, and don’t confuse the two jobs. The index finds the browser session. The order ID identifies the transaction. One visit can produce two orders, and one order can produce several webhook deliveries.

Object Created where What it does Needed at webhook time
Platform click ID Landing URL or platform cookie Links the conversion to an eligible ad click Yes, where the destination accepts it
Attribution index ID Your first-party endpoint Points to the stored browser record Yes
Checkout Session ID Payment system Identifies the payment attempt Yes, for retrieval and reconciliation
Order ID Your commerce system Identifies the transaction and controls duplicate counting Yes

Where the browser context gets lost

On the landing page, the browser can read URL parameters such as gclid or oppref and cookies written by your tags. On the hosted payment page your web container doesn’t run. Later, the webhook comes from the provider’s server and knows the session and payment status, nothing about the tab that started it.

A Stripe custom domain doesn’t change that design. With a custom domain, a paid Stripe feature (checked 2026-10-17), Checkout runs on your subdomain, so a cookie scoped to your parent domain can travel with requests to it. Your tags still don’t run on Stripe’s page, and the webhook still has no cookies.

The success redirect can’t repair it either. Some buyers close the tab, and delayed methods finish without the return page. Stripe’s fulfillment guidance requires a webhook path for that reason and warns that the handler can run more than once. That gives a clean diagnosis: if the paid order has no reference to a stored landing-page row, the break happened before the webhook.

The index row and its claim ticket

The index is a server-side lookup table. The row can hold gclid, gbraid, wbraid, fbclid or _fbc, _fbp, ttclid, oppref, the GA4 client and session IDs, UTMs, the entry page and timestamps. Only store fields you’re allowed to use and need. The ID should be random enough to resist guessing, free of personal data, and short enough for the checkout field that carries it. First-party describes who controls the row. It doesn’t exempt it from consent, notice, security or deletion duties. The first-party and third-party cookie guide covers the browser side.

A compact version, with illustrative names:

create table attribution_index (
  id            text primary key,       -- random, only [A-Za-z0-9_-]
  created_at    timestamptz not null,
  expires_at    timestamptz not null,
  click_ids     jsonb,                  -- gclid, gbraid, wbraid, fbc, fbp, ttclid, oppref
  ga_client_id  text,
  ga_session_id text,
  utm           jsonb,
  landing_url   text,
  consent       jsonb not null,         -- state, source, timestamp
  cart_ref      text                    -- what the paid order must match
);
create table processed_webhooks (provider_event_id text primary key);
create table sent_conversions   (order_id text, destination text, primary key (order_id, destination));

Carry the reference through checkout, with a fallback

When the visitor clicks Buy, the page sends the permitted context to your endpoint, which writes the row and returns the ID. Give that write a short time limit. If it fails, times out, or consent doesn’t allow advertising data, the checkout goes ahead without a reference. Refuse the attribution claim, never the purchase.

For a Checkout Session your server creates, Stripe defines client_reference_id as a string to “reconcile the Session with your internal systems”. An illustrative Node call:

const session = await stripe.checkout.sessions.create({
  mode: 'payment',
  line_items: [{ price: 'price_EXAMPLE', quantity: 1 }],
  client_reference_id: indexId,   // omitted when the index write failed
  success_url: 'https://example.com/thanks?session_id={CHECKOUT_SESSION_ID}',
});

Stripe Payment Links take the same value as a URL parameter, https://buy.stripe.com/...?client_reference_id=<indexId>. The Payment Links URL parameters page (checked 2026-10-17) limits it to alphanumerics, dashes and underscores, up to 200 characters, and says “Invalid values are silently dropped, but your payment page continues to work as expected.” An ID with a dot vanishes without an error, which is why the schema above restricts the character set. The Stripe conversion tracking guide covers Payment Links and Pricing Tables in more detail.

Other providers expose different fields. Treat each one as an adapter with a tested input and a tested webhook output, and never guess a field name from another checkout.

A flow diagram shows the landing page capturing click IDs, saving a first-party index, carrying its ID into hosted checkout, and using the paid webhook to load the original browser record.
The checkout transports the claim ticket. Your first-party store keeps the click record that the webhook needs later.

Rejoin the record in the webhook

Verify the webhook before trusting any order data. For Stripe, that means the raw request body, the Stripe-Signature header and the endpoint secret, as in its signature guide. Then confirm the paid state and read the reference.

const event = stripe.webhooks.constructEvent(rawBody, signature, endpointSecret);
if (seen(event.id)) return ack();                       // processed_webhooks
const s = event.data.object;
const paidEvent = event.type === 'checkout.session.completed'
  || event.type === 'checkout.session.async_payment_succeeded';   // delayed methods pay here
if (!paidEvent || s.payment_status !== 'paid') return ack();       // unpaid: wait for the async event
const row = s.client_reference_id ? await loadIndex(s.client_reference_id) : null;
const attribution = validRow(row, s) ? row : null;      // expired, mismatched or no consent -> null
if (!(s.amount_total > 0)) { queueTrialEvent(s, attribution); return ack(); } // $0 trial, no revenue
enqueueSends(orderIdFor(s), s, attribution);            // sent_conversions guards each destination
return ack();

Stripe’s fulfillment guide (checked 2026-10-17) handles both events in one handler. A delayed method such as a bank debit completes the session unpaid and sends checkout.session.async_payment_succeeded when the money arrives, so dropping that event loses the sale. Both paths share one order ID, and the sent_conversions key keeps them to one purchase per destination. The amount check matters because Stripe’s Checkout Session object marks a free-trial session paid once “the $0 trial invoice has been successfully processed”. Send that as a funnel event, not a purchase.

An absent ID, an expired row, a row whose cart doesn’t match the order, or a consent state that blocks advertising use all produce an explicit unattributed result. Don’t borrow the last click seen for the same email or fall back to a campaign. Those shortcuts make dashboards fuller by assigning revenue without evidence. Log the order ID and the reason instead.

Consent can change between capture and payment. Stripe notes that bank debits and vouchers can take 2 to 14 days to confirm. Store the consent source and timestamp with the row, apply later withdrawals to it, and read the consent state again when the send is built, not only at capture.

Why match quality drops when the join is missing

The webhook may still carry an email, phone, value and currency, and that can be enough for a destination to receive a Purchase. It’s weaker than what you had before the redirect. The lost row held the click ID that ties the order to an ad, the browser identifiers used for matching, the original session, and the consent state. The order ID stops one transaction from becoming two. The click ID connects that transaction to an ad interaction. A working webhook can coexist with weak campaign reporting: transport succeeded, the join didn’t.

For each platform’s matching fields, see the Facebook Conversions API guide. For ChatGPT Ads, the same architecture preserves oppref until the server conversion is ready.

Where server-side GTM fits

A server container receives the verified purchase, loads or receives the indexed context, and builds each platform’s payload. It’s the routing layer. The index itself belongs in a database built for lookups and retention, because a container variable isn’t a ledger and a cookie isn’t available to the webhook. ATA Edge is built on this pattern for Stripe, Hotmart and other checkouts: the index goes to the checkout, and the paid webhook brings it back.

Test the join, including the cases that should fail

Start one controlled visit with known test parameters and note the index ID your endpoint returns. Confirm the exact ID reaches the Checkout Session, complete a test payment, and check that the handler loads the expected row. Then check each destination for receipt, click attribution where it’s reported, and duplicate handling. Keep one receipt with timestamps and IDs so a later regression has something to compare against.

Then run the negative controls:

  • A valid paid webhook with no reference lands in the unattributed queue.
  • A reference with one character changed fails the lookup closed.
  • A valid reference from a different visit, pasted onto another cart, is rejected by the cart check.
  • The index write times out on purpose, and checkout still completes, unattributed.
  • Consent is denied at capture, and the row stores no advertising identifiers.
  • Consent is granted at capture and withdrawn before the webhook, and no advertising send goes out.
  • A replayed webhook doesn’t count the purchase again.
  • A delayed payment counts once, when checkout.session.async_payment_succeeded arrives.
  • A $0 trial session produces a funnel event and no purchase.
  • Two orders from one indexed visit stay two distinct transactions.
  • An expired row is reported as expired, not guessed.

Kwai is a concrete example of this handoff: the landing URL supplies click_id, while the server returns clickid. See the Kwai Events API guide for the exact fields and validation steps.