Pushing the ecommerce data stops working as soon as products data is being added.
So, for a Magento 2 integration, on the Success page I have this code:
<?php
$orderData = $block->getOrderData()
?>
<script>
var _paq = _paq || [];
var orderItems = JSON.parse("<?=$block->escapeJs($block->getOrderItemsData())?>");
for (const index in orderItems) {
_paq.push([
'addEcommerceItem',
orderItems[index].sku,
orderItems[index].name,
orderItems[index].category,
orderItems[index].price,
orderItems[index].qty
]);
}
_paq.push([
'trackEcommerceOrder',
'<?=$block->escapeJs($orderData['id'])?>',
'<?=$block->escapeJs($orderData['grand_total'])?>',
'<?=$block->escapeJs($orderData['sub_total'])?>',
'<?=$block->escapeJs($orderData['tax'])?>',
'<?=$block->escapeJs($orderData['shipping'])?>',
'<?=$block->escapeJs($orderData['discount'])?>'
]);
</script>
If I remove the addEcommerceItem
part, the order’s data is successfully sent to PIWIK, but as soon as I add it back in, no info is being sent (order or product data).
There are no JS errors in the console, so that can be ruled out as a probable cause.
This is the data from the _paq
array (1 item from the order, and the actual order’s data):
Any idea what might be going wrong / what am I missing?