This post has been archived
The content of this post has not been updated since 2016, and may be out of date. Extra care should be taken with any code provided.
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.
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...
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...
August 2023
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 2024
Cookieless website tracking is a method of collecting analytics data and monitoring website behaviour without the need for traditional browser cookies. Traditionally, cookies have been...
→ Continue reading"Cookieless website tracking and analytics"
November 2023
In today's digital age, establishing an online presence is crucial for businesses looking to promote their brand effectively. One powerful tool for achieving this is...
→ Continue reading"Creating a brand-promoting brochure website with WordPress "
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"