Sub topic 7
Cart events: add_to_cart, remove_from_cart, and view_cart
This chapter assumes you know how GA4 events and parameters work, how an items array is built, and how currency and value are sent. Cart events reuse those pieces. The work here is deciding what each event means, and what quantity and value describe in each one.
What the three cart events record
GA4 does not store a cart. It only records events, so any cart total you see in reports is computed from the events you sent. Each cart event describes one moment:
| Event | Fires when | `items` contains | `quantity` means |
|---|---|---|---|
| `add_to_cart` | A user adds product units to the cart | Only the products added in this action | Units added in this action |
| `remove_from_cart` | A user removes units from the cart | Only the products removed in this action | Units removed in this action |
| `view_cart` | The user opens the cart page or cart drawer | Every line currently in the cart | Units of that line in the cart now |
The first two events are changes (deltas). view_cart is a snapshot. Mixing these up is the most common cart tracking error.
Sending add_to_cart
Send currency, value, and an items array. value is the sum of price × quantity for the items in the event. The currency parameter is required whenever you send value, because GA4 needs it to interpret the number.
gtag('event', 'add_to_cart', {
currency: 'USD',
value: 49.98,
items: [
{
item_id: 'SKU_1001',
item_name: 'Trail Running Shoe',
item_brand: 'Acme',
item_category: 'Shoes',
item_variant: 'blue',
price: 24.99,
quantity: 2
}
]
});This event records two units at 24.99 each, so value is 49.98. If the user adds one more pair later, send a second add_to_cart with quantity: 1 and value: 24.99. Do not send quantity: 3.
Sending remove_from_cart
The structure matches add_to_cart. The items array lists only what was removed, and value is the worth of the removed units.
gtag('event', 'remove_from_cart', {
currency: 'USD',
value: 24.99,
items: [
{
item_id: 'SKU_1001',
item_name: 'Trail Running Shoe',
price: 24.99,
quantity: 1
}
]
});Fire this event for every route that removes units: the trash icon, a quantity stepper going down, and "remove all" buttons. A stepper going from 3 to 2 is a remove_from_cart with quantity: 1.
Sending view_cart
view_cart lists the full cart, with one entry per line. value is the sum across all lines.
gtag('event', 'view_cart', {
currency: 'USD',
value: 74.97,
items: [
{
item_id: 'SKU_1001',
item_name: 'Trail Running Shoe',
price: 24.99,
quantity: 2,
index: 0
},
{
item_id: 'SKU_2002',
item_name: 'Trail Socks',
price: 24.99,
quantity: 1,
index: 1
}
]
});Fire it when the cart view appears, not on every cart refresh. If the cart page reloads after each quantity change, that reload sends a new view_cart. Decide whether you want that, and keep the rule consistent.
Computing value in code
Do not type value by hand. Compute it from the same item objects you send, so the two numbers cannot drift apart. This helper works for all three events.
function sumValue(items) {
const total = items.reduce(
(sum, item) => sum + item.price * (item.quantity || 1),
0
);
// Round to cents to avoid floating-point noise such as 49.980000000000004.
return Math.round(total * 100) / 100;
}
function sendCartEvent(eventName, items) {
gtag('event', eventName, {
currency: 'USD',
value: sumValue(items),
items: items
});
}
sendCartEvent('add_to_cart', [
{ item_id: 'SKU_1001', item_name: 'Trail Running Shoe', price: 24.99, quantity: 2 }
]);A missing quantity is treated as 1, so the helper uses the same default.
What the events feed in reports
GA4 turns these events into metrics you can use in the Monetization reports and in explorations:
- Items added to cart counts the units from
add_to_cartevents, summingquantity. - Add-to-carts style user and event counts show how many people reached the cart step.
- Item-scoped dimensions, such as item name or category, split these counts by product.
Because units are summed, a wrong quantity changes your numbers directly. Sending quantity: 3 after a user already had 2 inflates "items added to cart" by 3 when only 1 unit was added.
Common errors
- Sending the cart total in
add_to_cart. The event should carry only the units added by this action. - Forgetting
currency. Without it GA4 cannot interpretvalue, and the value is not usable for revenue-style analysis. - No
remove_from_cart. Without it, add-to-cart counts only go up, and abandonment looks worse than it is. - Duplicate firing. A click handler bound twice, or an event sent from both a button click and a page script, doubles the count. Check each action in DebugView and confirm one event appears.
- Sending
valueas a string. Send49.98, not"$49.98". Use a number without symbols. - Inconsistent
item_id. If the product page sendsSKU_1001and the cart sends1001, GA4 treats them as two products and your funnel by item breaks.
Testing
Add a product, change its quantity, remove it, and open the cart while DebugView is open. Check that:
- Each action produces exactly one event.
- The
itemsarray holds only changed lines foradd_to_cartandremove_from_cart. view_cartholds every line.valueequals the sum ofprice × quantityin each event.
Exercise
A user has 2 pairs of SKU1001 (price 24.99) in the cart and clicks "+" once. Which event do you send, what are the quantity and value, and which event do you send when the user then opens the cart page, assuming they also hold 1 unit of SKU2002 at 10.00?
Show answer
Send addtocart with one item, SKU1001, quantity 1, and value 24.99 with a currency code. It lists only the added unit, not the new total of 3. When the user opens the cart, send viewcart with two items: SKU1001 with quantity 3 and SKU2002 with quantity 1. Its value is 3 × 24.99 + 10.00 = 84.97.