Sub topic 2
Designing the sale event
This chapter assumes you have a GA4 web data stream, Editor access to the property, and either access to the site's code or a Google Tag Manager container. You should be comfortable reading the GA4 Admin and Reports sections.
Designing the sale event
A sale is best recorded with the recommended purchase event. Fire it once, on the order confirmation page, after payment succeeds. Firing it on the checkout page or on a page reload can count the same sale more than once.
Adding value and currency
Two parameters let GA4 report revenue correctly:
| Parameter | Type | Purpose |
|---|---|---|
| `value` | number | Total order amount |
| `currency` | text (ISO 4217 code, e.g. `USD`) | Currency of `value` |
Send both on every purchase. Without currency, revenue totals cannot be converted or compared across markets.
Preventing duplicate sales with transaction_id
transaction_id is a unique order identifier, such as your order number. GA4 uses it to recognize repeat purchase events for the same order. Do not reuse an ID, and do not rely on GA4 to remove duplicates. Prevent them in your code, for example by checking a flag set after the first send.
Sending the event with gtag.js or Tag Manager
With gtag.js, place this on the 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 }
]
});With Google Tag Manager, push the data to the dataLayer and let a GA4 event tag forward 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 }
]
}
});Marking the event as a key event
A key event is an event you have chosen as a business outcome. To mark purchase:
- Open Admin, then Data display, then Events.
- Wait until
purchaseappears in the list. It appears after GA4 has received it at least once. - Turn on Mark as key event for
purchase.
Exercise
Why must transaction_id be unique for each order?
Show answer
GA4 uses it to recognize repeat purchase events. If two different orders share an ID, or one order is sent twice under different IDs, revenue and sale counts become wrong.