Deduplicate purchase
The failure
A confirmation page that pushes purchase on every load counts the order as many
times as the visitor reloads. A refresh, a back navigation, a shared link:
revenue climbs without a single extra sale.
Nothing flags it. GA4 deduplicates by transaction_id over a short window only,
and if the id is regenerated on every load, there is nothing left to deduplicate.
How it is built here
Three decisions, and all three matter:
- The id is created when the checkout is confirmed, not on the confirmation page. Generating it on arrival is exactly what makes it different on every reload.
- The lock stores the id, not a boolean. A boolean would block a second, legitimate order in the same session.
- The cart is emptied after the push, never before. Emptying first would
send a
purchasewith emptyitems— and since the event still fires, the funnel looks complete and the revenue is zero.
Checking it
Walk the funnel through to the confirmation. The
purchase event shows up in preview. Reload the page: it must not show up
again, and the displayed reference must be identical.
Then place another order: a new id is issued, and purchase fires again. That is
the expected behaviour — the lock prevents the duplicate, not the next sale.