Sub topic 6
Designing the Sale Event
Assume you have a GA4 web data stream installed, Editor access to the property, and a checkout that reaches an order confirmation page. You should also understand basic JavaScript or Google Tag Manager data layers.
A sale event records a completed transaction. GA4 provides the recommended event name purchase. Use this name instead of a custom name such as sale because GA4 reports and integrations recognize the recommended ecommerce schema.
Define when a sale happens
Send purchase only after the payment system confirms the order. Do not send it when someone clicks “Pay,” because the payment may fail or be abandoned.
The event should run once for each completed order. A page reload must not create a new order event. Your implementation needs a stable order identifier from the commerce system, such as T_12345.
Build the purchase payload
The core parameters are:
| Parameter | Purpose | Example |
|---|---|---|
| `transaction_id` | Identifies the order and supports duplicate prevention | `T_12345` |
| `value` | Total monetary value of the purchase | `59.98` |
| `currency` | Three-letter ISO 4217 currency code | `USD` |
| `items` | Products included in the order | An array of item objects |
Each item should have a stable item_id or a useful item_name. Include price and quantity so GA4 can calculate item-level results. Add tax, shipping, coupon, or affiliation when those values are available and match your reporting rules.
// Run after the payment provider confirms the order.
// Run once for this order confirmation.
gtag('event', 'purchase', {
transaction_id: 'T_12345',
value: 59.98,
currency: 'USD',
tax: 4.99,
shipping: 0,
items: [
{
item_id: 'SKU_123',
item_name: 'Trail Shoes',
price: 59.98,
quantity: 1
}
]
});Use the same currency for the event value and item prices. Do not put a currency symbol in value; send a number, not a string such as "$59.98".
Prevent duplicate purchases
Duplicate events commonly happen when the purchase code is placed on a confirmation page that users refresh, revisit, or save. A server-rendered page can also execute the code again after a payment retry.
Store an order’s analytics status on the server or use a reliable data-layer flag so the event is sent only when the order has not already been reported. Keep transaction_id unchanged across retries. Test both a first visit and a page reload.
If your business allows partial refunds, report refunds using the appropriate refund process rather than sending another purchase event. A second purchase would inflate revenue.
Check the design before marking it as a key event
First confirm that the event represents a completed sale and that its value agrees with your business definition of revenue. Then send test data and inspect the event in DebugView. After the event arrives consistently, mark purchase as a key event in GA4 if completed orders are an outcome you want to measure.
Exercise
Which parameter should remain the same when a customer reloads the order confirmation page?
Show answer
The original transaction_id should remain the same, and the implementation should avoid sending the purchase again.