๐ด 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โ
| Parameter | Type | Required |
|---|---|---|
currency | string | required |
value | number | required โ price ร quantity of added items |
items | array | required |
Item levelโ
item_idrequiredquantityrequired โ amount added (delta)pricerequired- Rest: recommended (see items)
Platformsโ
| Platform | Native event |
|---|---|
| GA4 | add_to_cart |
| Meta | AddToCart (with content_ids, contents: [{id, quantity}], value, currency) |
| Google Ads | Dynamic 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.
- โ
valueincludes shipping/tax โ merchandise only.