Saturday, 3 September 2016

How to Add Facebook Pixel Code to Magento Success Page

Now a day’s, New Facebook pixel code is more intricate way to Web developers. From top of Google analytics  we get more javascript to drop into all pages where we can grow under like & share buttons, analytics tracking, advert tracking. Code helps to work website neatly.
For process of adding a Successful order tracking. Place .phtml for success

Now, open the file


Facebook conversion tracking need the total order. Use the following php code to set last order to amount variable which was already in tracking code.

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

At last after adding Facebook conversion code. Replace 100000001 with value form of your facebook conversion code.  It appears twice in javascript and Image SRC. Make necessary changes but also 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 = '//';
  var ref = document.getElementsByTagName('script')[0];
  ref.parentNode.insertBefore(fpw, ref);
<noscript><img height="1" width="1" alt="" style="display:none" src=";value=<?php echo $amount; ?>&amp;currency=GBP" /></noscript>

You can now go ahead and test to confirm. 

No comments:

Post a Comment