Difference between revisions of "Magento Commerce Tracking"

From Market Ruler Help
Jump to: navigation, search
(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…')
 
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
+
<?php
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
+
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$items = $order->getAllItems();
+
$items = $order->getAllItems();
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
+
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
+
$js_items = array();
+
$js_items = array();
foreach ($items as $item) {
+
foreach ($items as $item) {
$js_items[] = array("order-item", $item->getPrice(), $item->getSku(), null, $item->getQtyOrdered());
+
$js_items[] = array("order-item", $item->getPrice(), $item->getSku(), null, $item->getQtyOrdered());
}
+
}
?>
+
?>
<script type="text/javascript">
+
<script type="text/javascript">
(function (w) {
+
(function (w) {
var
+
var
order = {
+
order = {
id: '<?php echo $order->getId(); ?>',
+
id: '<?php echo $order->getId(); ?>',
total: '<?php echo $order->getGrandTotal(); ?>',
+
total: '<?php echo $order->getGrandTotal(); ?>',
subtotal: '<?php echo $order->getSubtotal(); ?>',
+
subtotal: '<?php echo $order->getSubtotal(); ?>',
currency: '<?php echo $currency; ?>'
+
currency: '<?php echo $currency; ?>'
},
+
},
items = <?php echo json_encode($js_items); ?>;
+
items = <?php echo json_encode($js_items); ?>;
w._crq = w._crq || [];
+
w._crq = w._crq || [];
w._crq.push(['order', order.total, order.id, order.subtotal, order.currency]);
+
w._crq.push(['order', order.total, order.id, order.subtotal, order.currency]);
for (item in items) {
+
for (item in items) {
if (items.hasOwnProperty(item)) {
+
if (items.hasOwnProperty(item)) {
w._crq.push(item);
+
w._crq.push(item);
}
+
}
}
+
}
}(window));
+
}(window));
</script>
+
</script>
  
 
You should place the above code, along with the ConversionRuler tracking snippet, on your <code>success.phtml</code> page - the ordering of the code does not matter. It will record:
 
You should place the above code, along with the ConversionRuler tracking snippet, on your <code>success.phtml</code> page - the ordering of the code does not matter. It will record:

Revision as of 19:41, 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.