add_to_cart event
The add_to_cart event captures a critical moment—purchase intent. It logs when a user adds a product to their cart, providing insights into buying behavior, funnel drop-offs, and ad performance. Tracking it correctly ensures better retargeting, higher ROAS, and optimized conversions.
const addToCartEvent = {
event: "add_to_cart",
ecommerce: {
currency: "USD",
value: 89.98, // Adjusted total value after discount
items: [
{
item_id: "XYZ123",
item_name: "Premium Snack Pack",
discount: 5, // Per unit discount
item_brand: "TastyBites",
price: 49.99, // Original price per unit
quantity: 2,
item_category: "Bundles"
}
]
}
};
// Clear out previous ecommerce data
dataLayer.push({ ecommerce: null });
// Push the event to the dataLayer
dataLayer.push(addToCartEvent);