Difference between revisions of "Magento Commerce Tracking"
From Market Ruler Help
(Created page with 'Magento's order tracking can be tracked in the <code>success.phtml</code> page which, by default, is located at: app/design/frontend/base/default/template/checkout/success.phtm…') |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | Magento's order tracking can be tracked in the <code>success.phtml</ | + | Magento's order tracking can be tracked in the <span class="code">success.phtml</span> page which, by default, is located at: |
app/design/frontend/base/default/template/checkout/success.phtml | app/design/frontend/base/default/template/checkout/success.phtml | ||
Line 7: | Line 7: | ||
To add ConversionRuler tracking to the success page, add code like this to your order confirmation page: | To add ConversionRuler tracking to the success page, add code like this to your order confirmation page: | ||
− | + | <?php | |
− | + | $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId()); | |
− | + | $items = $order->getAllItems(); | |
− | + | $currency = Mage::app()->getStore()->getCurrentCurrencyCode(); | |
− | + | ||
− | + | $js_items = array(); | |
− | + | foreach ($items as $item) { | |
− | + | $js_items[] = array("order-item", $item->getPrice(), $item->getSku(), null, $item->getQtyOrdered()); | |
− | + | } | |
− | + | ?> | |
− | + | <script type="text/javascript"> | |
− | + | (function (w) { | |
− | + | var | |
− | + | order = { | |
− | + | id: '<?php echo $order->getId(); ?>', | |
− | + | total: '<?php echo $order->getGrandTotal(); ?>', | |
− | + | subtotal: '<?php echo $order->getSubtotal(); ?>', | |
− | + | currency: '<?php echo $currency; ?>' | |
− | + | }, | |
− | + | items = <?php echo json_encode($js_items); ?>; | |
− | + | w._crq = w._crq || []; | |
− | + | w._crq.push(['order', order.total, order.id, order.subtotal, order.currency]); | |
− | + | for (item in items) { | |
− | + | if (items.hasOwnProperty(item)) { | |
− | + | w._crq.push(item); | |
− | + | } | |
− | + | } | |
− | + | }(window)); | |
− | + | </script> | |
− | You should place the above code, along with the ConversionRuler tracking snippet, on your <code>success.phtml</ | + | You should place the above code, along with the ConversionRuler tracking snippet, on your <span class="code">success.phtml</span> page - the ordering of the code does not matter. It will record: |
* Action '''order''' with the first numeric value as the "total", the first text value as the order ID, the 2nd numeric values as the subtotal, and the 2nd text value as the currency used. | * Action '''order''' with the first numeric value as the "total", the first text value as the order ID, the 2nd numeric values as the subtotal, and the 2nd text value as the currency used. |
Latest revision as of 19:44, 24 November 2015
Magento's order tracking can be tracked in the success.phtml page which, by default, is located at:
app/design/frontend/base/default/template/checkout/success.phtml
If your Magento installation has an alternate theme, it may be located in a different subfolder.
To add ConversionRuler tracking to the success page, add code like this to your order confirmation page:
<?php $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId()); $items = $order->getAllItems(); $currency = Mage::app()->getStore()->getCurrentCurrencyCode(); $js_items = array(); foreach ($items as $item) { $js_items[] = array("order-item", $item->getPrice(), $item->getSku(), null, $item->getQtyOrdered()); } ?> <script type="text/javascript"> (function (w) { var order = { id: '<?php echo $order->getId(); ?>', total: '<?php echo $order->getGrandTotal(); ?>', subtotal: '<?php echo $order->getSubtotal(); ?>', currency: '<?php echo $currency; ?>' }, items = <?php echo json_encode($js_items); ?>; w._crq = w._crq || []; w._crq.push(['order', order.total, order.id, order.subtotal, order.currency]); for (item in items) { if (items.hasOwnProperty(item)) { w._crq.push(item); } } }(window)); </script>
You should place the above code, along with the ConversionRuler tracking snippet, on your success.phtml page - the ordering of the code does not matter. It will record:
- Action order with the first numeric value as the "total", the first text value as the order ID, the 2nd numeric values as the subtotal, and the 2nd text value as the currency used.
- One action order-item for each item in the cart.
If you would like to customize this code for your own purposes (or include tracking in non-JavaScript browsers), please contact support.