<script type="text/javascript">

    /*** GA4 ***/

    window.dataLayer = window.dataLayer || [];

    dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
    dataLayer.push({
        event: "purchase",
        ecommerce: {
            transaction_id: "{{ config('site.tnx_prefix') }}_{{ order.getId() }}",
            value: parseFloat({{ order.getTotalCost() }}),
            tax: parseFloat({{ order.getVatCost() }}),
            shipping: parseFloat({{ order.getDelivery().cost }}),
            currency: "GBP",
            items: [

                {% for itemRow in order.getItems() %}

                {
                    item_id: "{{ itemRow.item_id }}",
                    item_name: "{{ itemRow.item_name | e('js') }}",

                    item_brand: "{{ itemRow.brand_name | e('js') }}",
                    item_category: "{{ itemRow.main_category_name | e('js') }}",
                    item_variant: "{{ itemRow.size | e('js') }}",

                    price: parseFloat({{ itemRow.item_price }}),
                    quantity: parseInt({{ itemRow.quantity }}),
                },

                {% endfor %}

            ],
        }
    });

</script>
