(718) 690-7302 [email protected] Google AdWords, Google Shopping, Facebook Ads Management


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:

	//Get Order Number & Order Total
	$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
	$amount = number_format($order->getGrandTotal(),2);

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:

<?php echo $amount; ?> // Order Total
<?php echo $this->getOrderId() ?> // Order Number

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

<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 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>

Image Credit: Search Engine Journal

26 Comments to "How To Setup Conversion Tracking In Magento"

  1. Reply
    January 5, 2010 at 10:04 AM

    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.

    • Menachem Ani
      Michael J. Kaye
      January 5, 2010 at 10:12 AM

      Hi autoguy

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


      • Reply
        January 5, 2010 at 10:27 AM

        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?

        • Reply
          January 5, 2010 at 10:32 AM

          Hey, I actually found a typo in my code, it’s working now, so thanks a lot!

  2. Reply
    March 16, 2010 at 4:36 PM

    tried your code but no result :(

    the problem is with amount

  3. Reply
    April 6, 2010 at 8:39 PM

    thanks for this useful post! i did as you told us, and it works now!
    thanks again!

  4. Reply
    November 3, 2010 at 9:35 AM


    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


    • Menachem Ani
      Michael J. Kaye
      November 3, 2010 at 12:37 PM


      Unfortunately, I am not familiar with Prestashop.

  5. Reply
    February 21, 2011 at 10:26 AM


    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

  6. Reply
    June 6, 2011 at 2:26 PM

    Do you know how to pull specific items for tracking?

  7. Reply
    December 21, 2011 at 7:39 AM

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

    Grtz from Holland

    • Menachem Ani
      Menachem Ani
      December 22, 2011 at 11:25 AM

      I just tested on and it works properly. Not sure about 1.6.1

  8. Reply
    May 11, 2012 at 12:48 AM

    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.

  9. Reply
    October 11, 2012 at 10:41 PM

    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?

  10. Reply
    October 29, 2012 at 11:45 AM

    We have a free ROI tracker extension that adds this for you http://www.magentocommerce.com/magento-connect/catalog/product/view/id/14817/

  11. Reply
    April 11, 2013 at 9:55 AM

    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


  12. Reply
    Ravi Patel
    March 18, 2014 at 4:53 AM

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

  13. Reply
    March 20, 2014 at 12:39 PM

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

  14. Reply
    March 6, 2015 at 7:55 AM

    How can I also pull in the customer type (new or returning) and number of units?

  15. Reply
    March 6, 2015 at 12:21 PM

    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?

  16. Reply
    Steve Racicot
    July 22, 2015 at 11:39 AM

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

  17. Reply
    August 14, 2015 at 1:31 AM

    Thanks for this useful post! We will try it out

  18. Reply
    Ulysses Alves
    November 12, 2015 at 6:02 AM

    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.

  19. Reply
    P Patel
    February 11, 2016 at 1:37 AM

    i have already add this code on website but how to attach it on google tag manager

Trackbacks for this post

  1. How To Track Magento eCommerce Sales In Google Anayltics - eCommerceCircle

Leave a comment

Your email address will not be published. Required fields are marked *