Skip to main content

๐Ÿ”ด Phase 1 โ€” Coreย ยทย Mid-funnel signal for retargeting + ROAS optimization.

add_to_cart

When to pushโ€‹

After the server confirms the cart mutation (not on optimistic click). Avoids ghost events when the API fails.

quantity in the event = the amount added, not the total in the cart.

Exampleโ€‹

async function addToCart(product, qty) {
const res = await fetch('/api/cart/add', {
method: 'POST',
body: JSON.stringify({ sku: product.sku, quantity: qty })
});
if (!res.ok) return;

window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: 'EUR',
value: product.price * qty,
items: [
{
item_id: product.sku,
item_name: product.name,
item_brand: 'Biosphere',
item_category: product.category,
item_variant: product.variant,
price: product.price,
quantity: qty
}
]
}
});
}

Parametersโ€‹

Event levelโ€‹

ParameterTypeRequired
currencystringrequired
valuenumberrequired โ€” price ร— quantity of added items
itemsarrayrequired

Item levelโ€‹

  • item_id required
  • quantity required โ€” amount added (delta)
  • price required
  • Rest: recommended (see items)

Platformsโ€‹

PlatformNative event
GA4add_to_cart
MetaAddToCart (with content_ids, contents: [{id, quantity}], value, currency)
Google AdsDynamic remarketing audience

Edge casesโ€‹

Increasing quantity of an existing cart itemโ€‹

Push with the delta, not the new total.

// User clicks + on an item already at 2 โ†’ goes to 3
// Push with quantity = 1 (the delta)
{
items: [{ item_id: 'BIO-CRM-001', quantity: 1, price: 42.00, ... }]
}

Multi-add (bundle / "shop the look")โ€‹

All items in the same push:

{
event: 'add_to_cart',
ecommerce: {
currency: 'EUR',
value: 84.00,
items: [
{ item_id: 'BIO-CRM-001', quantity: 1, price: 42.00, ... },
{ item_id: 'BIO-SER-002', quantity: 1, price: 42.00, ... }
]
}
}

Pitfallsโ€‹

  • โŒ Push on click before API response โ†’ ghost events.
  • โŒ Push total cart quantity instead of added quantity.
  • โŒ value includes shipping/tax โ€” merchandise only.