Hi Cédric, thanks for reaching out!
The recommended approach for both - datalayer events structure and for the e-commerce tracking PPTM tags is described In this thread.
That said - it’s obviously not the only way. You could use a PPTM datalayer variable, but you would need to fetch the whole ecommerce
object and then iterate through on the custom HTML tag level. Unfortunately, it’s not possible to refer to nested attributes of a datalayer object directly. It would look roughly like this:
For cart update:
<script>
var _paq = _paq || [];
var orderDetails = {{ ecommerce object }};
var products = orderDetails.purchase.products;
var cart_amount = orderDetails.purchase.actionField.revenue;
products.forEach(function (product) {
_paq.push(["addEcommerceItem", product.id, product.name, product.category, product.price, product.quantity])
});
_paq.push(["trackEcommerceCartUpdate", cart_amount]);
</script>
For order confirmation
<script>
var _paq = _paq || [];
var orderDetails = {{ ecommerce object }};
var products = orderDetails.purchase.products;
var order_id = orderDetails.purchase.actionField.id;
var grand_total = orderDetails.purchase.actionField.revenue;
products.forEach(function(product){
_paq.push(["addEcommerceItem",product.id, product.name, product.category, product.price, product.quantity])
});
_paq.push(["trackEcommerceOrder",order_id, grand_total]);
</script>
{{ ecommerce object }}
is a PPTM datalayer variable ecommerce
.
I hope the above helps!
Thanks,
Piotr