Magento Commerce Tracking

From Market Ruler Help
Revision as of 19:41, 24 November 2015 by Admin (talk | contribs) (formatting)
Jump to: navigation, search

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.