Sub topic 3
Instrumenting a purchase journey with recommended events
A funnel exploration can only measure what the property has recorded. If add_to_cart never fires, the "Add to cart" step shows zero users, however well you configure the exploration. This chapter covers how to send the events that become the steps of a purchase funnel, and how to check that they arrive intact.
Prerequisites assumed
- You know that GA4 records behavior as events, and that events carry parameters (see the previous chapter on events and parameters).
- You can edit the site's tags, either directly with
gtag.jsor through Google Tag Manager. - You have at least Analyst access to the GA4 property. Editor access is needed to change data stream settings.
Why recommended events
GA4 has four kinds of events: automatically collected, enhanced measurement, recommended, and custom. Recommended events are ones Google has already named and defined, along with the parameters each one should carry. For ecommerce, these include view_item, add_to_cart, begin_checkout, add_payment_info and purchase.
Using the exact recommended names has three practical benefits:
- Ecommerce reports, such as Monetization, populate automatically from them.
- Revenue, item and currency fields are recognized without extra setup.
- Anyone who later joins the project can read your funnel steps and know what they mean.
A custom event named addedToCart would work in a funnel too. However, it would not feed the ecommerce reports, and event names are case sensitive, so Add_To_Cart and add_to_cart count as different events.
The shape of a purchase journey
The funnel in this tutorial has four steps. Each step maps to one event.
Real stores often have more events, such as view_cart, add_shipping_info and add_payment_info. Add them only if you want to see drop-off at those points. Each extra step adds a place where an instrumentation mistake can distort the numbers.
Sending the early steps
The gtag.js calls below fire at the first three steps. Each event carries currency, value and an items array. Each element of items describes one product.
// Step 1: user views a product
gtag('event', 'view_item', {
currency: 'USD',
value: 29.99,
items: [{ item_id: 'SKU_123', item_name: 'Canvas Tote', price: 29.99 }]
});
// Step 2: user adds it to the cart
gtag('event', 'add_to_cart', {
currency: 'USD',
value: 29.99,
items: [{ item_id: 'SKU_123', item_name: 'Canvas Tote', price: 29.99, quantity: 1 }]
});
// Step 3: user starts checkout
gtag('event', 'begin_checkout', {
currency: 'USD',
value: 29.99,
items: [{ item_id: 'SKU_123', item_name: 'Canvas Tote', price: 29.99, quantity: 1 }]
});Notes on these calls:
item_idoritem_nameis required in each item. Senditem_idconsistently, because it is the stable key for comparing products.valueshould equal the sum ofpricemultiplied byquantityacross the items. Mismatches make revenue figures disagree between reports.currencyis a three-letter ISO 4217 code. If you sendvaluewithoutcurrency, the revenue is not counted properly.
Closing the funnel with purchase
The purchase event ends the journey and is the most important one to get right, because revenue reporting depends on it.
gtag('event', 'purchase', {
transaction_id: 'T_12345',
currency: 'USD',
value: 29.99,
items: [{ item_id: 'SKU_123', item_name: 'Canvas Tote', price: 29.99, quantity: 1 }]
});transaction_id is the order identifier from your system. GA4 uses it to avoid counting the same transaction twice, so a page reload on the confirmation screen does not inflate revenue. The identifier must be unique per order and the same value must never be reused for a different order.
Where to place the calls
Tie each event to the user action, not just to a page load.
| Event | Fire when | Common placement mistake |
|---|---|---|
| `view_item` | The product detail page or modal is shown | Firing on category listings, which counts browsing as product views |
| `add_to_cart` | The cart actually accepts the item | Firing on button click even if the add fails |
| `begin_checkout` | The user enters the checkout flow | Firing on every checkout step, which repeats the event |
| `purchase` | The order is confirmed by the server | Firing before payment succeeds |
In a single-page application, page loads do not happen on navigation. Send events from the code that handles the action, such as a click handler or a successful API response, rather than relying on a page-view trigger.
Using Google Tag Manager
If you use Tag Manager, the usual pattern is to push ecommerce data to the data layer and let a GA4 event tag read it. Clear the previous ecommerce object before each push so values from an earlier event do not carry over.
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null }); // clear the previous ecommerce object
dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: 'USD',
value: 29.99,
items: [{ item_id: 'SKU_123', item_name: 'Canvas Tote', price: 29.99, quantity: 1 }]
}
});In the GA4 event tag, set the event name to add_to_cart and enable sending ecommerce data from the data layer. A custom event trigger named add_to_cart then fires the tag.
Verifying before you build
Check the data before you open the Funnel exploration.
- Open Admin > DebugView and enable debug mode, for example with the Tag Assistant or the
debug_modeparameter. Walk through the purchase journey yourself. - Confirm each event appears in the order you expect, and expand it to inspect
currency,valueanditems. - Check Reports > Monetization > Ecommerce purchases a day later to confirm item data and revenue appear.
- Compare the number of purchases in GA4 with orders in your own system for the same day. A small gap is normal, since consent choices and ad blockers prevent some events from being collected. A large gap points to a firing problem.
Common instrumentation gaps
- Missing steps for some paths. If a "Buy now" button skips the cart, users reach
begin_checkoutwithout ever sendingadd_to_cart. In a closed funnel they are not counted at all, because they did not enter at step 1. - Events fired in the wrong order. If
begin_checkoutfires beforeadd_to_cartfor some flows, sequence-based funnels show fewer completions. - Inconsistent names.
Purchase,purchaseandorder_completeappear as separate events. Settle on one convention and audit for strays in Reports > Engagement > Events. - Cross-domain breaks. If checkout lives on another domain, configure cross-domain measurement. Otherwise the user appears as new on the checkout domain and the journey is split in two.
- Duplicate firing. Both a hard-coded tag and a Tag Manager tag send the same event, so counts double.
Marking the key event
Once purchase is reliable, mark it as a key event in Admin > Events. Key events (formerly called conversions) are surfaced in conversion reports and can be used for bidding when the property is linked to Google Ads. A funnel does not require this, but it makes the final step easy to find in other reports.
Exercise
A store's confirmation page can be reloaded, and its funnel shows more purchases than the order system records. Name two changes that would address this, and say which GA4 field helps recognize duplicates.
Show answer
First, send a unique transaction_id with every purchase event, since GA4 uses it to avoid counting the same transaction twice. Second, guard the call in code so it fires once per order, for example by storing the transaction_id in localStorage and skipping the event if it is already stored. Also check that no second tag, such as one hard-coded and one in Tag Manager, sends the same event.
Exercise
A "Buy now" button sends users from the product page directly to checkout, skipping the cart. What happens to those users in a closed funnel whose first step is view_item and whose second step is add_to_cart, and how could you handle it at instrumentation time?
Show answer
They do not progress past step 2, because no add_to_cart event exists for them, so they look like drop-off even though they may purchase. At instrumentation time, send add_to_cart when "Buy now" is clicked, or define the funnel steps to match what the flow really sends, for example by making begin_checkout the step that both paths share.