How To Setup Conversion Tracking In Magento

3rd Party Conversion Tracking

Magento Commerce has the ability to track eCommerce sale with Google Analytics out of the box (more on that in a future post). Something that a lot of merchants struggle with is how to set up conversion tracking for other tracking software or comparison shopping engines.

How To

Here is an easy hack to track conversions for Shopzilla, PriceGrabber and the likes:

Open the file:

app\design\frontend\XXXX\XXXX\template\checkout\success.phtml

At the end of the file, add the following code, this will create two variables with the order number and the order total:

[code lang=”php”]<?php
//Get Order Number & Order Total
$order = Mage::getModel(‘sales/order’)->loadByIncrementId(Mage::getSingleton(‘checkout/session’)->getLastRealOrderId());
$amount = number_format($order->getGrandTotal(),2);
?>[/code]

After the above code snippet, copy and paste the tracking code from the third party analytics software of comparison shopping engine. Insert the following variable where they suggest placing the order ID and the order total:

[code lang=”php”]<?php echo $amount; ?> // Order Total
<?php echo $this->getOrderId() ?> // Order Number[/code]

Here is a code example for the Shopzilla conversion tracking tool:

[code lang=”JavaScript”]<script language="javascript">
var mid = ‘XXXXX’; // Your Shopzilla Merchant ID
var cust_type = ”;
var order_value = ‘<?php echo $amount; ?>’; // Order Amount
var order_id = ‘<?php echo $this->getOrderId() ?>’; //Order Number
var units_ordered = ”;
</script>
<script language="javascript" src="https://www.shopzilla.com/css/roi_tracker.js"></script>
<script language="JavaScript" src="https://eval.bizrate.com/js/pos_193511.js" type="text/javascript"></script>[/code]

Image Credit: Search Engine Journal

Comments (26)

  1. autoguy:

    Hey, thanks for the article! Any insight on how to include tracking code for MS AdCenter (Bing) in Magento? I tried putting it into app/code/core/Mage/Checkout/Block/Onepage/success.php but it throws an error message after checkout.

    1. Michael J. Kaye:

      Hi autoguy

      Please see the above article — you will want to add the code in: app\design\frontend\XXXX\XXXX\template\checkout\success.phtml

      –M

      1. autoguy:

        Thanks – but I’m still getting an error message:

        Parse error: syntax error, unexpected ‘<' in l/app/design/frontend/default/default/template/checkout/success.phtml on line 78

        any insight?

  2. Fabien:

    HI.

    I am working on prestashop e-commerce solution.
    Can you advice in wich file i am suposed to included your code ?

    Prestashop is written in smarty language and i couldn’t found where to put your code.
    Is it into : Theme/mytheme/order-confirmation.tpl ?

    Thanks for your reply

    Regards

  3. Kurt:

    Hi,

    thanks for the information. Unfortunately, the code doesn’t work for 1.4.2! Do you have a solution for 1.4.2?

    Thanks, Kurt

  4. TennisArtikelen:

    Didnt work for me in magento 1.6.1 . Ill try another solution now, I will get back at you!

    Grtz from Holland

  5. Guy:

    Hi there, do you know how to do this in MagentoGO? i’m having a lot of difficulty using the blocks and front end apps.. thanks.

  6. Chris:

    Thanks for the great article – It has been really useful. However… I’m now useing 2 comparison shopping engines and have installed the conversion code for both of them on the conformation page. When I get a sale it gets reported to both of them and the sale shows up in both their stats. Is there an easy way of sorting out where the sale came from?

  7. Zoe:

    Hey there is I followed ur instruction.And evrything seems to be fine after a order I checked all fetching correctly .But the tracker is not working.
    Is the tracker take some time to update..Please help me.

    Thanx in advance

    ZOE

  8. Ravi Patel:

    hey guys any buddy tell me how i can create fb ads tracking extension in magento1.8 ??? any links regarding these ???

  9. niceone:

    I’ve put on a Facebook conversion tracking code on the success.phtml page, and this method simply works. Thank you.

  10. Chris:

    I have tried adding this but the code is being commented out from the php opening until right after (‘sales/order’)->

    Does anyone have any ideas why this would be happening?

  11. Steve Racicot:

    This doesnt work in 1.9 CE. It displays a “Fatal error: Call to a member function loadByIncrementId() on a non-object” Error.

  12. Ulysses Alves:

    The rwd package has no file success.phtml in folder app/design/frontend/rwd/default/template/checkout. I changed the package to default, because the default package has the success.phtml file. But I wonder: should this happen or the file success.phtml should be in the folder? May this be because of a problem in the deployment so that the file was not copied to folder app/design/frontend/rwd/default/template/checkout? Or even worse, someone could have maliciously deleted the file?

    Thank you for your help.

Comments are closed.