Pushing ecommerce data not working when products are added

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):
Screenshot 2022-07-04 at 09.36.19

Any idea what might be going wrong / what am I missing?

I’d start with checking the field types. Some of them are strings, others are floats. Please check this guide.

I have added the data formatting and it still doesn’t work.
And keep in mind with/without formatting, the functionality breaks only after we I try to add the products data to the order.

Hi. I just tested the simplest example directly via browser’s console:

_paq.push(['addEcommerceItem',
            "mySKU",
            "itemName",
            "itemCat",
            22.5,
            8
        ]);

_paq.push([
        'trackEcommerceOrder',
        "myID123",
        22.5,
        22.5,
        0,
        0,
        0
    ]);

The second call generated the following request:
https://myinstance.piwik.pro/ppms.php?idgoal=0&ec_id=myID123&revenue=22.5&ec_st=22.5&ec_tx=0&ec_sh=0&ec_dt=0&ec_items=%5B%5B%22mySKU%22%2C%22itemName%22%2C%22itemCat%22%2C22.5%2C8%5D%5D&idsite=40446cce-14be-445c-b625-56833a7066ab&rec=1&r=018178&h=9&m=9&s=41&url=http%3A%2F%2Fmydev.com%2F&_id=fdaaaa4bb36c9380&_idts=1657868838&_idvc=1&_idn=0&_viewts=1657868838&send_image=0&ts_n=jstc_tm&ts_v=2.7.1&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=0&java=0&gears=0&ag=0&cookie=1&res=1512x982&gt_ms=2&pv_id=y3ss54

As you can see, the item is included in the request.

Here’s how it looks in the tracker debugger / session log:

There must be something wrong with formatting. I’d suggest printing the commands that are created via the for loop to be able to troubleshoot what’s wrong in there.