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.
My Magento Expertise
If you are planning a new e‑commerce store, considering a platform upgrade or looking for ongoing Magento support, I can provide the expertise you need. Based in Northern Ireland and working with clients locally and internationally, I deliver solutions that help businesses grow.
More Magento posts
—
Magento database structure
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 Magento database structure is crucial…
—
Accessibility in ecommerce websites
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 rush to create visually appealing…
—
Using Magento to get small businesses online
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 tailored to their needs. Scalability…
Continue reading "Using Magento to get small businesses online"
—
How can I speed-up my Magento website?
Speed optimisation is crucial for a Magento website as it directly impacts user experience, conversions, and search engine rankings. You should prepare your server so it is set-up to use…
More SEO posts
—
Structured data for SEO
Adding structured data to a website is one of those steps that often gets overlooked, yet it can make a real difference to how a site performs in search engines.…
—
Simple Analytics: A privacy-focused alternative to Google Analytics
In an era where digital privacy concerns are at the forefront of online discourse, many organisations are reassessing their tools to ensure compliance with data protection laws and maintain user…
Continue reading "Simple Analytics: A privacy-focused alternative to Google Analytics"
—
Cookieless website tracking and analytics
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 a key component in tracking…
Continue reading "Cookieless website tracking and analytics"
—
Creating a brand-promoting brochure website with WordPress
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 WordPress, a versatile content management…
Continue reading "Creating a brand-promoting brochure website with WordPress "