Hi Frédéric, ideally, the CMS pushes all purchase / cart / product data to the dataLayer.
In the TagManager variables section, you can retrieve those variables and use them in the corresponding tag.
It becomes a bit tricky, if one of the array nodes is an array (e.g. multiple products). Then, you’ll have to loop through this node and push the necessary infos to the addEcommerceItem method (within the tag).
For example (untested code):
<script type="text/javascript">
var productItems = {{Ecommerce - Product items}};
for (let i = 0; i < productItems.length; ++i) {
//Add product
_paq.push(['addEcommerceItem',
productItems[i].sku,
productItems[i].name,
productItems[i].categories,
productItems[i].price,
productItems[i].quantity
]);
}
if(productItems.length > 0) {
_paq.push(['trackEcommerceCartUpdate', {{Ecommerce - Cart total}}]);
}
</script>
the “addEcommerceItem” method call to add all the products is needed in two places - before calling the “cartUpdate” and before tracking the “ecommerceOrder”.
You can either double the “addEcommerceItem” code to be included in the cartUpdate and the ecommerceOrder tag, or you can build an “addEcommerceItem” tag that is called with a higher priority than “cartUpdate” or “ecommerceOrder” to add the products to the ecommerce tracking before the server requests are issued.
Cart update fires as soon as the customer puts the first or additional products into his/her cart, “ecommerceOrder” is called, as soon as the purchase is confirmed (“thank you page”).
The variables used in the example are structured in a different way, compared to the tutorial, so you have to build the variables the way you need them for your case. The total revenue can also be a nested array type like in the tutorial, that’s just personal taste.