# Browser fix or server-confirmed sending

Where to fix what the reconciliation found, how to build a hold-until-paid sender, and why a Measurement Protocol backfill does not repair attribution. Measurement Protocol facts were checked on 2026-10-17 against the sending, use-case, reference and validation pages in `sources.yaml`.

## Decision rules

Compute from the classified orders of one frozen period:

- `control_miss_rate`: the miss rate of the in-page checkout flow with at least 100 eligible orders and the lowest miss rate (Query 7). It carries the losses every flow shares: consent, blockers, closed tabs.
- `recoverable_share`: for each redirect and delayed-payment flow (3-D Secure, wallets, bank redirects, buy now pay later, bank transfer, direct debit, invoices), the segment miss rate minus the control miss rate, floored at zero, times the segment's eligible orders; summed and divided by eligible orders. Query 7 returns it. It is the share of orders server-confirmed sending would add back.
- `placement_fire`: analytics-only `unpaid` transactions plus orders with `fired_before_business_ts`.
- `redirect_share` and `delayed_share`: report them for context only. A high redirect share whose flows return reliably costs nothing; a small flow that loses most of its orders still shows in the recoverable share.

Then:

- Fix in the browser when `recoverable_share` is at most 2% (the default investigate line), `placement_fire` is zero or the contract counts placed orders, and the defects found are triggers, payloads, ID formats or reloads.
- Move to server-confirmed sending when `recoverable_share` is above 2%, or the contract counts paid orders and `placement_fire` is above zero.
- In-page flows that stay above the unexplained-gap threshold after browser fixes, with measured blockers as the cause: server sending helps counts only under option (a) for orders without a `client_id` (below). Decide with the owner whether those counts are worth a new user per order and no channel.
- Never run two `purchase` senders for one order in production. The browser can keep funnel events (`begin_checkout`, `add_payment_info`, or a custom placement event) while the server owns `purchase`.

The 2% line is a default, not a vendor rule. Below it, the orders a server build would add back cost more to build than they are worth; above it, the gap sits in flows the browser cannot see. Record the agreed line in the contract (`server_recoverable_share_min`).

## Browser fixes

- Trigger on the platform's checkout event or a data layer push made when payment is confirmed. Never on a URL alone: upsell steps, order-status pages and return paths reuse or skip URLs.
- Build the payload from order data rendered by the server on the confirmation page. Data layer state set before a payment redirect is gone after the return.
- Push `{ ecommerce: null }` before each ecommerce event, as Google's GTM examples do, so items from an earlier step cannot leak into `purchase`.
- Send once per order. Best: the server records that the purchase was sent and renders that flag into the page. Fallback: a sent marker keyed by order ID in browser storage, which fails across devices and private windows.
- One ID format (the contract's key), `value` as items after discounts without tax and shipping, the presentment currency, and numbers, not text.
- Payment provider domains showing as referral sources after the return change attribution, not counts. Add them as unwanted referrals only after tracing one journey. Google's path, checked 2026-10-17: Admin, Data collection and modification, Data streams, Web, the stream, Configure tag settings, Show all, List unwanted referrals. Matching events get `ignore_referrer` set to `true`. The article does not say the change applies to past data; assume it does not.
- Retest per payment method in a test environment, then re-run the reconciliation on a frozen period after the release.

## Hold until paid, then send

The browser keeps the session context; the server decides that the order is paid and sends `purchase` once.

1. At checkout, where consent permits, read `client_id` and `session_id` from the Google tag with the `get` command (`gtag('get', 'G-XXXXXXXXXX', 'client_id', callback)`, and the same for `session_id`). Do not parse cookies. Send both, with the consent state and the checkout ID, to your backend and store them on the order. With a payment provider, keep them in your database and put only an opaque reference in the provider's metadata.
2. Record whether capture worked. Google's callback receives `undefined` when a field is unset, and the call never runs when a blocker stopped the tag or it had not loaded before a fast redirect. Store `client_id_captured` (true or false) on the order. Among checkouts whose recorded consent allows analytics, the share without a `client_id` is a direct blocker meter; report it per checkout flow.
3. The browser does not send `purchase`.
4. When payment is confirmed (a verified webhook or the provider's payment status read from its API), create one delivery record per order and destination, unique on the order key. Webhook redeliveries and a second event type for the same payment then resolve to the same record.
5. Build the event: the stored `client_id`; `session_id` in the event parameters; `transaction_id` set to the contract's order key; `value` as items after discounts without tax and shipping; `currency`; `tax`; `shipping`; `items`. Google's reference asks for `session_id` and `engagement_time_msec` for accurate session metrics; send engagement time only if you measured it.
6. Timing. Session attributes apply only when the event carries `session_id`, the request arrives no later than 24 hours after the session started, and an overridden `timestamp_micros` sits between the session's start and end. Send at confirmation without overriding the timestamp. Overriding it with a payment time after the session ended breaks the condition. Separately, Google asks that events meant to be processed with tagged events arrive within 48 hours of the original client-side event.
7. Payment confirmed more than 24 hours after the session started (bank transfer, invoices): the event cannot take the session's attributes. Decide in the contract (`paid_after_24_hours`): send at payment time without session attribution, accepting that the order counts but has no channel, or keep these orders out of GA4 and report them from the warehouse. Never move the timestamp back into the session.
8. No `client_id` captured and consent did not deny analytics. Decide in the contract (`orders_without_client_id`):
   - (a) Send with a per-order generated `client_id` and a marker parameter such as `data_source` set to `server_no_client`. The order counts as a new user with no session and no channel.
   - (b) Do not send, and report these orders from the warehouse.
   - Only (a) recovers blocker losses, and only in counts; neither recovers attribution. Never reuse one constant ID across orders.
9. Consent. Apply the consent recorded at checkout. If analytics was denied under the site's policy, do not send. Server sending does not raise the consent ceiling; it removes losses from redirects and closed tabs, and from blockers only under option (a). Fill the request's `consent` fields (`ad_user_data`, `ad_personalization`) from the recorded state.
10. Validate on the validation endpoint (`/debug/mp/collect`) with `validation_behavior` set to `ENFORCE_RECOMMENDATIONS`. It does not check the API secret and its events do not reach reports. The production endpoint returns `2xx` even when the payload is malformed or not processed, so a `2xx` proves transport only.
11. Privacy. Keep the API secret on the server and out of logs; it travels in the request URL. GA4 data redaction runs client side on web streams and does not prevent personal data arriving through Measurement Protocol (checked 2026-10-17), so build the payload from an allowlist of fields and keep personal data out of it and out of delivery logs.
12. Record each delivery as pending, sent, rejected or unknown. A timeout is unknown, not failed: retry with the same key under a written policy and reconcile.
13. Limits checked 2026-10-17: up to 25 events per request and 25 parameters per event. Rules that create or modify events in the GA4 interface do not run on Measurement Protocol events, so send the final event name and parameters.

The confirmation page can still show the order from server data. It must not send `purchase`.

## Moving from browser to server

- Shadow first: for one frozen period, the server builds the event and logs it, or sends it to a test property. Reconcile the shadow output with the orders. Expected coverage: eligible orders minus documented consent exclusions, and minus orders without a `client_id` under option (b).
- Cut over in one release: disable the browser `purchase` and enable the server sender together. An overlap doubles counts in the export and in any destination without deduplication.
- Expect a step change. Redirect and delayed flows start appearing, and the channel mix can shift. Annotate the date and tell report consumers before they see it; the series before and after is not comparable.
- When the sender being removed carried no attribution (one constant user, no sessions), counts can fall while channel data does not change. Size the drop in advance from Query 2 (`browser_only` or `server_only` for that sender), frame it as reporting completeness and agree it before the release.

## Why a Measurement Protocol backfill loses session attribution

A backfill sends purchases for orders the reconciliation found missing. By then:

- The period is frozen, so at least 6 days have passed since it ended. Session attributes need the request within 24 hours of the session start, so a backfill can never qualify.
- Backdating stops at 72 hours. Older timestamps are accepted but moved to 72 hours ago under relaxed validation (the default), or rejected under `ENFORCE_RECOMMENDATIONS`. A backfilled week lands on the wrong days as well as without sessions.
- Without the original browser `client_id` the event joins no browser. A made-up ID creates a new user per order; one constant ID puts every purchase on one user.
- Events sent cannot be recalled by the sender.

The result is higher revenue totals with no session source. In practice these rows show up as Direct or Unassigned, which inflates those channels and lowers every other channel's conversion rate.

Rules if a backfill is approved anyway:

- Only orders confirmed missing after the freeze, never duplicates, late rows or analytics-only orders.
- Re-check the export for each ID immediately before sending; skip any that appeared.
- The contract's `transaction_id` and value rule; the stored `client_id` when it exists, never a placeholder.
- A marker parameter so the rows can be separated later, for example `data_source` set to `backfill`.
- Written approval with the order list, the expected effect on reports and the date shift. The usual better answer is to keep finance revenue in the warehouse and report GA4's gap rather than fill it.
