Ecommerce Tracking Analytics Magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<?php | |
// Transaction Data | |
$orderID = $this->getOrderId(); | |
$order = Mage::getModel('sales/order')->loadByIncrementId($orderID); | |
$orderTotal = $order->getGrandTotal(); | |
$orderDetails = $order->getData(); | |
$couponCode = $orderDetails['coupon_code']; | |
?> | |
<!-- script per ecommerce analitycs --> | |
<script type="text/javascript"> | |
dataLayer.push({ | |
"ecommerce": { | |
"currencyCode": "EUR", | |
"purchase": { | |
"actionField": { | |
"id": "<?php echo $orderID; ?>", | |
"affiliation": "SITENAME", | |
"revenue": "<?php echo $order->getGrandTotal(); ?>", | |
"tax":"<?php echo $order->getTaxAmount(); ?>", | |
"shipping": "<?php echo $order->getShippingAmount(); ?>", | |
"coupon": "<?php echo $couponCode; ?>" | |
}, | |
"products": [ | |
<?php $numitem = 0; $numitem = count($order->getAllItems()); | |
foreach ($order->getAllVisibleItems() as $item){ | |
$numitem = $numitem - 1; ?> | |
{ | |
"name": "<?php echo str_replace('"', "", $item->getName()); ?>", | |
"id": "<?php echo $item->getSku(); ?>", | |
"price": "<?php echo $item->getPrice(); ?>", | |
"quantity": <?php echo $item->getQtyOrdered(); ?> | |
} | |
<?php if ($numitem != 0) {echo ",";} | |
} ?> | |
] | |
} | |
} | |
}); | |
</script> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment