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.
<?php //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'; (function(){ 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); })(); </script> <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=100000001&value=<?php echo $amount; ?>¤cy=GBP" /></noscript>
You can now go ahead and test to confirm.
January 2024
For small businesses aiming to establish a formidable online presence and drive sales, Magento emerges as a powerful e-commerce platform offering a suite of features... Continue reading "Using Magento to get small businesses online"
October 2023
The database structure of Magento is designed to store and manage various aspects of an e-commerce website, including products, orders, customers, and more. Understanding the... Continue reading "Magento database structure"
August 2023
In the digital age, where online shopping has become an integral part of our lives, ecommerce websites hold the key to business success. Amidst the... Continue reading "Accessibility in ecommerce websites "
June 2019
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... Continue reading "Remove outdated content from Google Search Results"
November 2016
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.... Continue reading "All-in-one Google Analytics tracking in Magento"
November 2016
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... Continue reading "All-in-one Facebook Pixel Code for Magento ecommerce"