Sub topic 3
Instrumenting a Purchase Journey with Recommended Events
Assume you understand GA4 events and parameters, and you can edit the code that runs on an ecommerce site. A funnel is only as useful as its event data. Before building the exploration, make sure each important purchase action sends the correct event name and parameters.
Choose events that represent the journey
GA4 recommended ecommerce events provide a shared vocabulary for shopping actions:
view_item: a user views a product.add_to_cart: a user adds a product to the cart.begin_checkout: a user starts checkout.purchase: an order is completed.
The event name describes the action. Parameters add detail about that action. For example, item_id identifies a product, price gives the product price, and quantity gives the number purchased.
A basic purchase funnel can use view_item, add_to_cart, and purchase. Add begin_checkout when checkout is a meaningful stage that you want to diagnose.
// Step 1: the 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: the user adds the product 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: the 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
}
]
});
// Step 4: the order is completed.
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
}
]
});The purchase event should run only after the order succeeds. Send transaction_id as a unique order identifier. GA4 uses it to help prevent duplicate purchase counting when a confirmation page is reloaded.
Keep event data consistent
Use the same product identifier across all events. Keep currency in ISO 4217 format, such as USD or EUR. The value parameter should agree with the items and quantity. If the cart contains several products, include every product in the items array and calculate the total correctly.
A common instrumentation error is sending a custom event such as product_added while the funnel expects add_to_cart. The events may describe the same action, but GA4 treats their names as different. Another error is sending an event without the parameters needed for a breakdown, such as item name or device-relevant context.
Verify before building the funnel
Use DebugView or another test property to confirm that:
- Each action sends exactly one intended event.
- The event name uses the expected spelling.
items,value,currency, andtransaction_idcontain valid values.- The purchase event appears only after a successful order.
- Events arrive in the intended order for a test user.
Exercise
A funnel shows many add_to_cart users but no purchase users. What should you check first?
Show answer
Confirm in DebugView that the site sends the purchase event after a successful order, uses the exact event name, and includes a unique transaction_id.