Adding cart data to data layer


From the documentation I understood that we can use key value pairs to add data to the data layer.
I need to add the products from the cart to the data layer but I’m missing some pointers. Should it be added in a bulk, meaning in a ‘products’ key that contains an array with all the products - so a single push() to the data layer - or do I need to add it separately - a push() for each product in the cart?

Hi. You can push whole objects. Just keep in mind that our datalayer variables don’t work yet with nested values. So, the more flat the object is, the easier it is to extract all the data.

Our datalayer works in a similar way to the one from GTM. So those examples should all work fine: GTM Guide: dataLayer.push with examples - Analytics Mania

This was really useful. Thank you!