Sub topic 2
Product discovery: view_item_list, select_item, and view_item
This chapter assumes you know GA4 events and parameters, basic JavaScript objects and arrays, and how the GA4 tag is installed on a site. Every e-commerce event carries an items array. Each item is an object with fields such as item_id, item_name, price, and quantity.
Product discovery events
view_item_list: a shopper sees a list of products, such as a category page or related-products strip.select_item: a shopper clicks a product from a list.view_item: a shopper opens a product detail page.
gtag('event', 'view_item_list', {
item_list_id: 'related_products',
item_list_name: 'Related products',
items: [
{ item_id: 'SKU_1001', item_name: 'Trail Running Shoe', price: 24.99, index: 0 }
]
});
gtag('event', 'select_item', {
item_list_id: 'related_products',
item_list_name: 'Related products',
items: [
{ item_id: 'SKU_1001', item_name: 'Trail Running Shoe', price: 24.99, index: 0 }
]
});
gtag('event', 'view_item', {
currency: 'USD',
value: 24.99,
items: [
{ item_id: 'SKU_1001', item_name: 'Trail Running Shoe', price: 24.99, quantity: 1 }
]
});Cart events
add_to_cart and remove_from_cart need currency and value. Set value to the price multiplied by the quantity. For two shoes at 24.99, value is 49.98. view_cart carries the same fields and reports the cart contents.
Checkout events
begin_checkout: the shopper starts checkout.add_shipping_info: includes ashipping_tierparameter, such as "Ground".add_payment_info: includes apayment_typeparameter, such as "Credit Card".
The purchase event and transaction_id
purchase records a completed order. Give each order a unique transaction_id. GA4 uses it to find duplicates, so a page reload must not send the same ID twice. Send tax and shipping as separate parameters, not inside value.
Implementing e-commerce events with gtag.js
Call gtag directly on the page after the order is confirmed:
gtag('event', 'purchase', {
transaction_id: 'T_12345',
currency: 'USD',
value: 49.98,
tax: 4.00,
shipping: 5.99,
items: [
{ item_id: 'SKU_1001', item_name: 'Trail Running Shoe', price: 24.99, quantity: 2 }
]
});Implementing e-commerce events with the GTM dataLayer
Google Tag Manager (GTM) reads events from window.dataLayer. Clear the ecommerce object before each push so old items do not carry over:
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: 'view_item',
ecommerce: {
currency: 'USD',
value: 24.99,
items: [
{ item_id: 'SKU_1001', item_name: 'Trail Running Shoe', price: 24.99, quantity: 1 }
]
}
});Exercise
A shopper adds three pairs of shoes at 24.99 each to the cart. What value should the addtocart event send, and why?
Show answer
74.97. The value is the price multiplied by the quantity (24.99 × 3), and it is sent with a currency code.