Warning: Your browser is very out-of-date. You should upgrade to a better browser.

Update: Instead of this, try the All-in-one Facebook Pixel Code method. It’s easier to maintain.

Facebook Pixel Code is a new and even more complicated way to annoy web developers, so on top of all the Google Analytics we now have even more random JavaScript to drop into pages already growing under the weight of like and share buttons, analytics tracking, advert tracking on top of the code that actually makes the website work. Good times.

Anyhoo, this is the process for adding a successful order tracking. It all takes place on the success.phtml page or your theme so go ahead and open the file: app\design\frontend\PACKAGE\THEME\template\checkout\success.phtml

Facebook conversion tracking requires the order total. Add the following PHP to set the last order to an amount variable which can be reused later in the tracking code.

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

Finally, add the Facebook conversion code itself. Be sure to substitute the 100000001 below with the value form your Facebook conversion code – it appears twice in the JavaScript and the Image SRC. Also you may need to modify the currency parameter, again it appears twice.

<script type="text/javascript">
var fb_param = {};
fb_param.pixel_id = '100000001';
fb_param.value = '<?php echo $amount; ?>';
fb_param.currency = 'GBP';
  var fpw = document.createElement('script');
  fpw.async = true;
  fpw.src = '//connect.facebook.net/en_US/fp.js';
  var ref = document.getElementsByTagName('script')[0];
  ref.parentNode.insertBefore(fpw, ref);
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=100000001&value=<?php echo $amount; ?>&currency=GBP" /></noscript>

You can now go ahead and test to confirm.


Magento is a feature-rich ecommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their ecommerce store.

About Magento Ecommerce · Magento Posts

Related Magento Posts

Magento December 2021

Optimising Magento 2 in Easy Steps

Some (fairly) simple step-by-step instructions to ensure your Magento 2 store is running the best it can. While most of these options should only require...
Magento September 2021

The Future of Magento

The [Mage Open Source Community Alliance](https://www.mage-os.community/) have published an open letter to the Magento community to announce a new initiative designed to focus on ensuring...
Magento July 2021

Magento 2 Blog Extensions

While Magento isn't the go-to platform for blogs it can be useful for store owners to have a quick and easy way to post updated...

More MagentoSEO Posts...

Related SEO Posts

Notes SEO June 2019

Remove outdated content from Google Search Results

From time to time unwanted pages can appear in Google Search Results. Could be a temporary page, old content or even a test page that's...
Magento SEO November 2016

All-in-one Google Analytics tracking in Magento

Simple single script to add Google’s conversion tracking to your Magento ecommerce website. The code should be added into the footer.phtml file within your current template....
Magento SEO November 2016

All-in-one Facebook Pixel Code for Magento ecommerce

Simple single script to add Facebook’s Pixel Code tracking to your Magento ecommerce website. The code should be added into the head.phtml file within your...

More MagentoSEO Posts...