Sub topic 6
Designing the Sale Event
This chapter covers how to design the purchase event, the event GA4 uses to record a sale. It assumes you have a GA4 web data stream, you know the difference between an event and a parameter, and you have read the chapters on event types and on deciding what counts as a sale for your business. Marking the event as a key event comes in a later chapter.
Why the sale event deserves care
A lead event usually carries a rough estimate. A sale carries real money, and that money flows into revenue reports, Google Ads bidding, and finance comparisons. Small design mistakes, such as a missing currency or a double-fired event, produce numbers that look plausible but are wrong. Wrong revenue is worse than missing revenue, because people trust it.
Design the event before you write any code. Decide four things:
- Which moment is the sale.
- Which event name represents it.
- Which parameters describe it.
- Which system sends it.
Choose the moment of the sale
The sale moment is the point where the business considers the order real. For most online shops this is the order confirmation page, shown after payment succeeds. Avoid these earlier moments:
- Clicking the "Pay" button. The payment can still fail.
- Reaching the checkout page. This is a
begin_checkoutoradd_payment_infostep, not a sale. - Redirecting to an external payment provider. The user may never return.
If your payment provider confirms payments asynchronously (bank transfers, invoices, some wallets), the confirmation page may show before the money arrives. In that case, decide with the business whether a sale means "order placed" or "payment received". The first is simpler to measure in the browser. The second usually needs a server-side event, which is outside this chapter.
Use the recommended purchase event
GA4 defines a recommended event named purchase. Prefer it over a custom name such as order_complete for three reasons:
- GA4's ecommerce reports (Monetization section) read from
purchaseand its item data. - The
purchaseevent populates the built-in revenue metrics, such as Purchase revenue and Total revenue. - Google Ads and other integrations recognize it without extra mapping.
A custom event name would work as a key event, but it would not feed the ecommerce reports.
Required and useful parameters
The table below lists the parameters that matter for a sale.
| Parameter | Status | Purpose |
|---|---|---|
| `transaction_id` | Strongly recommended | Unique order ID. Used to ignore duplicate purchases. |
| `value` | Required for revenue reporting | Order total as a number. |
| `currency` | Required if `value` is sent | Three-letter ISO 4217 code, such as `USD`. |
| `items` | Required for item-level reports | Array of products in the order. |
| `tax`, `shipping`, `coupon` | Optional | Extra order detail. |
Two rules save most of the trouble here.
First, value must be a number, not a string. Send 59.98, not "$59.98". A currency symbol or a thousands separator can cause the value to be dropped or read as zero.
Second, if you send value without currency, GA4 does not report that revenue correctly. Always send both together.
Decide what `value` contains
value is a business decision as much as a technical one. Agree on whether it includes tax and shipping. A common choice is the sum of item prices times quantities, minus discounts, without shipping and tax. Whatever you choose, apply it everywhere, and write it down. Otherwise GA4 revenue will never match the revenue in your shop backend, and nobody will know why.
Describe the items
Each object in items needs item_id or item_name (preferably both). Add price and quantity so GA4 can compute item revenue. Optional fields such as item_category and item_brand enable richer breakdowns later.
A purchase event with gtag.js
This is the event as it is sent with gtag.js, on the order confirmation page.
// Fire once on the order confirmation page
gtag('event', 'purchase', {
transaction_id: 'T_12345',
value: 59.98,
currency: 'USD',
items: [
{
item_id: 'SKU_123',
item_name: 'Trail Shoes',
price: 59.98,
quantity: 1
}
]
});In real code, the values come from the order, not from literals. Your template or backend should fill in the transaction ID, total, and items from the confirmed order.
The same event through Tag Manager
If the site uses Google Tag Manager, the page pushes the data to the dataLayer, and a GA4 event tag forwards it.
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null }); // clear the previous ecommerce object
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: 'T_12345',
value: 59.98,
currency: 'USD',
items: [
{ item_id: 'SKU_123', item_name: 'Trail Shoes', price: 59.98, quantity: 1 }
]
}
});The line dataLayer.push({ ecommerce: null }) matters. The dataLayer merges objects, so without clearing, fields from an earlier ecommerce push (for example an old items list) can leak into the purchase. In Tag Manager, the GA4 event tag should have the event name purchase and "Send Ecommerce data" enabled, with the data source set to the Data Layer. The trigger is a Custom Event trigger matching purchase.
How a sale flows through the system
The diagram shows the path from the confirmed order to the GA4 reports.
Prevent duplicate sales
The confirmation page can load more than once for one order. Typical causes:
- The customer refreshes the page.
- The customer bookmarks the page or returns through the browser's back button.
- A confirmation email links to the same page.
- Both gtag.js and a Tag Manager tag fire on the same page.
GA4 uses transaction_id to recognize a repeat. If an order with the same ID has been recorded, GA4 does not count its revenue again. This works only if the ID is present, unique per order, and identical across repeats. Do not use a timestamp or a random value generated on page load. That creates a new ID for each load and defeats the check.
The transaction_id check does not cover every case. Treat it as a safety net and also guard in your own code. A simple approach is to remember in the browser that an order was already reported:
function sendPurchaseOnce(order) {
var key = 'ga4_purchase_' + order.id;
if (window.localStorage.getItem(key)) {
return; // already reported from this browser
}
window.localStorage.setItem(key, '1');
gtag('event', 'purchase', {
transaction_id: order.id,
value: order.total,
currency: order.currency,
items: order.items
});
}This guard covers refreshes in the same browser. It does not cover a customer who opens the link on another device, which is why transaction_id remains necessary.
Double tagging
Duplicate sales often come from two tracking setups running together, for example a hard-coded gtag.js snippet left on the site after a Tag Manager migration. Symptoms include purchase counts that are exactly double the shop's order count. Check that only one mechanism sends purchase. In DebugView, one order should produce one purchase event.
Refunds and cancellations
GA4 has a recommended refund event, which takes the same transaction_id and the refunded value (and items for partial refunds). Sending it keeps revenue closer to reality. Many teams skip it at first. If you do, note in your documentation that GA4 revenue is gross of refunds, so nobody compares it to net revenue by mistake.
Edge cases to plan for
- Multiple currencies. Send the currency the customer paid in. GA4 converts for reporting in the property's reporting currency, but it needs the correct code on each event.
- Free orders. A sale with a value of
0is still apurchase. Decide whether free orders count as sales for your business. If not, do not send the event for them. - Subscriptions. Send
purchasefor the first payment. Whether renewals are sent from the browser depends on whether the customer is present. Renewals usually happen on a server, with no page to carry the tag. - Consent. If the customer declines analytics consent, the event may not be sent or may be recorded in a limited form. The purchase counts in GA4 can therefore be lower than shop orders. This gap is expected and later chapters cover consent.
- Personal data. Do not put email addresses, names, or phone numbers in any parameter, including
transaction_idand item names. Use an internal order number.
Checklist before moving on
- The event name is exactly
purchase, in lowercase. - It fires once per confirmed order, on the confirmation step.
transaction_idis unique and stable per order.valueis a number andcurrencyis a valid code.itemshas at leastitem_idoritem_name, pluspriceandquantity.- Only one tool sends the event.
Exercise
A shop's GA4 shows 412 purchases for a week, but the shop backend shows 206 orders. Each GA4 purchase has a transaction_id. Name two likely causes and how you would check each.
Show answer
The most likely causes are double tagging and a non-stable transaction ID. For double tagging, look for a hard-coded gtag.js purchase snippet alongside a Tag Manager purchase tag, and in DebugView confirm whether one test order produces two purchase events. For an unstable ID, check whether transaction_id is generated on page load, such as from a timestamp or random value, instead of coming from the order. Reload the confirmation page and compare the IDs sent. A count of exactly double points to double tagging.
Exercise
Rewrite this event so it is correct: gtag('event', 'Purchase', { transaction_id: '[email protected]', value: '$1,249.50', items: [{ item_name: 'Laptop' }] });
Show answer
Use the lowercase name purchase. Replace the email with an internal order number, so there is no personal data. Send value as the number 1249.50 and add currency: 'USD'. Add price and quantity to the item, and an item_id if available. For example: gtag('event', 'purchase', { transaction_id: 'T_98765', value: 1249.50, currency: 'USD', items: [{ item_id: 'SKU_LT1', item_name: 'Laptop', price: 1249.50, quantity: 1 }] });