I want to add a data Layer to the confirmation.tpl so that I could fire the GA e-commerce tag via the Tag Manager once the customer clicks on "Confirm".
I tried using this code:
Code: Select all
<script>
dataLayer = [{
'transactionId': '<?php echo $order_id ?>',
'transactionTotal': <?php echo $total ?>,
'transactionTax': <?php echo $tax ?>,
'transactionShipping': <?php echo $shipping ?>,
<?php
$n=sizeof($order_data['products']);
for ($i=0; $i < $n; $i++) {
?>
'transactionProducts': [{
'sku': '<?php echo $product['product_id'] ?>',
'name': '<?php echo $product['name'] ?>',
'price': <?php echo $product['price'] ?>,
'quantity': <?php echo $product['quantity'] ?>
}]
<?php } ?>
}];
</script>
Thanks & best,
Torge