Sub topic 9
The purchase event and transaction_id
This chapter covers the purchase event, which GA4 uses to record revenue. It assumes you can already build an items array, set currency and value, and send events with gtag.js. You should also know the funnel events that come before a purchase.
What the purchase event does
The purchase event marks a completed transaction. It is the event GA4 uses to calculate purchase revenue, transactions, and the "Purchases" count. Every revenue report in GA4 depends on it, so mistakes here spread into every later report.
The event carries the same building blocks as the earlier funnel events, plus a few extra parameters.
| Parameter | Required | Purpose |
|---|---|---|
| `transaction_id` | Yes | A unique ID for the order, used for deduplication. |
| `currency` | Yes | A three-letter ISO 4217 code such as `USD`. |
| `value` | Yes | The numeric value of the purchase. |
| `items` | Yes | The products bought. |
| `tax` | No | Tax amount, sent as its own parameter. |
| `shipping` | No | Shipping cost, sent as its own parameter. |
| `coupon` | No | Order-level coupon code. |
A complete purchase event
gtag('event', 'purchase', {
transaction_id: 'T_12345',
currency: 'USD',
value: 49.98,
tax: 4.00,
shipping: 5.99,
coupon: 'SUMMER_SALE',
items: [
{
item_id: 'SKU_1001',
item_name: 'Trail Running Shoe',
price: 24.99,
quantity: 2,
index: 0
}
]
});Here value is 49.98, which is 24.99 multiplied by 2. Tax (4.00) and shipping (5.99) are not included in value. They travel as separate parameters.
Why transaction_id matters
The transaction_id identifies one order. GA4 uses it to avoid counting the same order twice. If two purchase events arrive with the same ID, GA4 keeps only one of them in its processed e-commerce data.
Duplicate purchases happen more often than you might expect:
- A customer reloads the order confirmation page.
- A customer returns to the confirmation page from a bookmark or an email link.
- Both a tag in the page and a server-side call report the same order.
- A single-page app fires the event again when the route re-renders.
Without a unique ID, each of these would inflate your revenue. With one, GA4 can recognize the repeats.
Rules for a good transaction_id
- Use your own order number, so you can match GA4 data to your order system.
- Make it unique per order, never reused for a later order.
- Keep it stable. The same order must always produce the same ID.
- Send it as a string, not a number that might be reformatted.
- Never leave it empty and never use a placeholder like
undefinedororder. A constant value would cause every order after the first to be treated as a duplicate.
Deduplication has limits
Deduplication is applied when GA4 processes data, so the same ID can still appear in DebugView or Realtime several times. Deduplication is also tied to the ID within a property, so a reused ID from a different order may be dropped. If your system recycles IDs (for example, resets its counter in a test environment), real orders can go missing. Test orders sent to a production property should use a clearly separate ID pattern, such as a TEST_ prefix, so you can find them later.
When to fire the event
Fire purchase once, when the order is confirmed. Two common approaches work:
- Confirmation page load. Fire on the "thank you" page. Guard against reloads by storing a flag, such as the order ID in
localStorage, and skipping the event if it already exists. - Server confirmation. Fire after the payment provider confirms success. This handles customers who close the browser before reaching the thank-you page, but it needs a server-side method (covered in a later chapter).
The following sketch shows a client-side guard.
function trackPurchaseOnce(order) {
var key = 'ga4_purchase_' + order.id;
if (localStorage.getItem(key)) {
return; // Already reported in this browser.
}
gtag('event', 'purchase', {
transaction_id: order.id,
currency: order.currency,
value: order.itemsTotal,
tax: order.tax,
shipping: order.shipping,
items: order.items
});
localStorage.setItem(key, '1');
}The guard only protects one browser. GA4's own deduplication covers the rest.
How the funnel leads to a purchase
The purchase is the last step of the funnel. Each earlier event feeds the same items, currency, and value logic.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Missing `transaction_id` | Reloads create duplicate revenue. | Always send the order number. |
| `value` as a string like `"$49.98"` | Revenue is not read as a number. | Send a plain number: `49.98`. |
| Missing `currency` | Revenue is not computed correctly. | Send an ISO code with every monetary event. |
| Tax and shipping added to `value` | Revenue is overstated compared with item revenue. | Keep `value` to the items total, as your reporting convention requires. |
| Event fired on payment click, not confirmation | Failed payments count as sales. | Fire after the order is confirmed. |
| Different `price` in `items` and the order system | Item revenue and orders disagree. | Use the final unit price. |
Check how your business defines revenue before choosing what goes into value. Whatever you decide, apply the same rule on every page and every platform. Mixed rules make comparison with your order system impossible.
Checking your work
Open DebugView and complete a test order. Confirm that exactly one purchase event appears, that transaction_id, currency, and value are present, and that the items list shows the expected products. Later, compare the purchase count and revenue in the reports against your order system for the same period. Small differences are normal because of consent choices and ad blockers. Large or growing gaps point to a tracking problem.
Exercise
A customer reloads your order confirmation page three times. Your tag sends a purchase event each time with transactionid "T9001" and value 80.00. What should GA4 report, and what should you change on your site to avoid relying on that result?
Show answer
GA4 deduplicates by transaction_id, so the processed data should show one purchase of 80.00, not three. The site should still be changed so the event fires only once, for example by storing the order ID in localStorage and skipping the event when it is already stored, or by firing the event from a server confirmation. Deduplication is a safety net, not a fix for a repeating trigger.
Exercise
An order has two items at 15.00 each, tax of 3.00 and shipping of 4.00. Using the convention in this chapter, what should value be, and where do tax and shipping go?
Show answer
value is 30.00 (2 × 15.00). Tax (3.00) and shipping (4.00) are sent as separate tax and shipping parameters, not added to value.