Documentation Fundamentals

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.

Screenshot of the 'Add to Cart' button on Korres product detail page
The 'Add to Cart' button on a Korres product detail page

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

  • items is required. Each item should have at least item_id or item_name set (ideally both).
  • If you use value (highly recommended), also set currency. value should be the sum of price * quantity for 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

javascript
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
        }]
    }
});
Show all code

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.