2

I am looking to add the following tracking code to the checkout confirmation page on our magento site but am unsure on what to add/change so that it reflects the order details. Can anyone help?

<script type="text/javascript">
            var _caq = _caq || [];
            var products = [];
            products.push({Sku: 'ProductID', UnitPrice: 'item price here', Quantity: 'quantity here'});
            products.push({Sku: 'ProductID', UnitPrice: 'item price here', Quantity: 'quantity here'});
            _caq.push(["Order", {OrderId: 'OrderID', Revenue: 'oVal', CurrencyCode: '3 letter currency code here', Products: products}]);
</script>
6

This would go in your success page template, of course. The default one is located at app/design/frontend/base/default/template/checkout/success.phtml:

<?php
    $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
    $items = $order->getAllItems();
    $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
?>

<script type="text/javascript">
            var _caq = _caq || [];
            var products = [];
            <?php foreach ($items as $item){
                    echo "products.push({Sku: '{$item->getSku()}', UnitPrice: '{$item->getPrice()}', Quantity: '{$item->getQtyOrdered()}'});\n";
                }
             echo "_caq.push(['Order', {OrderId: '{$order->getId()}', Revenue: '{$order->getGrandTotal()}', CurrencyCode: '{$currency}', Products: products}]);"; ?>
</script>
  • That's great thanks Don. Is there a subtotal alternative for getGrandTotal()? – user9539 Jun 25 '14 at 15:45
  • Several, actually! getSubtotal() will work, also getSubtotalInclTax() if you want tax added. Here's a good reference: freegento.com/doc/functions_0x67.html#index_g – Don Jun 25 '14 at 15:47
  • Exactly what I needed! :D Thanks for this answer! – jehzlau Aug 12 '17 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.