The add_to_cart Event in Google Analytics 4 (GA4)
The add_to_cart event in Google Analytics 4 (GA4) is used to track when a user adds a product to their shopping cart.
For most stores, this is an early but strong purchase signal: a user might browse products (view_item), compare items, and leave—but once something lands in the cart, purchase intent is usually much higher.
The add_to_cart event is one of the e-commerce events in GA4, meaning it should be enriched with items (product data) and typically also value and currency.
Implementation
The best place to trigger add_to_cart is the moment the action was successful—that is, after your store confirms the item is in the cart (or after the cart state has been updated in the frontend).
Required fields & value logic
itemsis required. Each item should have at leastitem_idoritem_nameset (ideally both).- If you use
value(highly recommended), also setcurrency.valueshould be the sum ofprice * quantityfor the added items—excluding shipping and taxes.
Quantity & repeated adds
It’s completely normal for a user to add the same item multiple times or increase the quantity.
In these cases, you should track the quantity being added (not necessarily the total quantity in the cart), so the event accurately reflects the specific action.
Outside of product detail pages
The product detail page isn’t always the only place where users can add products to their cart. If products can be added from the checkout or upsell modules, an add_to_cart event should still be triggered.
The same applies to stores where users can add products directly from product lists without going to the product detail page.
dataLayer
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "add_to_cart",
ecommerce: {
currency: "EUR",
value: 59.80,
items: [{
item_id: "SKU12345",
item_name: "Superfood Powder",
item_category: "Superfoods",
item_variant: "500g",
item_brand: "MySupplements",
price: 29.90,
quantity: 2
}]
}
});
Common pitfalls
- Sending event before success: Especially with API-based carts, adding items can fail (inventory not up-to-date, validation errors, etc.). Only track after the action succeeds.