Facebook conversion tracking in Magento

Facebook conversion tracking in Magento

July 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Facebook conversion tracking in Magento

Integrating Facebook Conversion Tracking in Magento

Tracking conversions from your Magento store using Facebook Pixel is a powerful way to optimize your marketing campaigns. However, inserting the tracking code directly into the success.phtml file may not always be straightforward due to Magento’s template structure.

Let me guide you through a more effective approach to implement this conversion tracking:

Understanding Magento’s Template Structure

In Magento, themes are composed of various XML files that define layout structures and HTML files (phtml) that render dynamic content. The success.phtml file is responsible for displaying the order confirmation page after a successful checkout.

However, if you’re unable to find the <head> tags in this particular file, it’s likely because Magento uses a different mechanism for including head elements - the head block defined in layout XML files.

Locating the Head Block in Layout XML

To locate where the Facebook conversion code should be inserted, navigate to your theme folder located at:

app/design/frontend/{package}/{theme}/layout

Look for the file named checkout_onepage_success.xml. Within this file, you’ll find a block definition that looks something like this:

<block type="core/text" name="head_child">
  <action method="setText">
    <text>Your Facebook Conversion Code goes here</text>
  </action>
</block>

Inserting the Facebook Conversion Code

Now, let’s insert your Facebook conversion tracking code into this text block. Open the checkout_onepage_success.xml file and find the <head_child> block.

Replace the <text> element with your actual Facebook pixel code:

<block type="core/text" name="head_child">
  <action method="setText">
    <text>
      <!-- Facebook Conversion Code for track facebook -->
      <script type="text/javascript">
        var fb_param = {};
        fb_param.pixel_id = 'xxxxxxxxxxxx';
        fb_param.value = '0.00';
        fb_param.currency = 'USD';
        (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=6015688541915&amp;amp;value=0&amp;amp;currency=USD" />
      </noscript>
    </text>
  </action>
</block>

Testing the Integration

After updating the file, clear your Magento cache and refresh your browser. The Facebook conversion tracking code should now be present on your order success page.

Remember to replace ‘xxxxxxxxxxxx’ with your actual pixel ID in the fb_param.pixel_id line.

Best Practices for Facebook Pixel Tracking

To make the most of your Facebook Pixel data:

  1. Ensure accurate event triggering: Double-check that you’re tracking events like ‘Purchase’, ‘AddToCart’, and ‘ViewContent’ correctly.
  2. Set up custom conversions: Create custom conversions in the Facebook Ads Manager to track specific user actions relevant to your business.
  3. Monitor performance: Regularly review the data in your Facebook Pixel dashboard to optimize your marketing campaigns.

For a more detailed guide on implementing advanced Facebook Pixel events and best practices, I recommend checking out this comprehensive resource from Laravel Company.

Conclusion

Successfully integrating Facebook conversion tracking in Magento requires understanding the theme’s layout XML files rather than individual PHP templates. By modifying the checkout_onepage_success.xml file, you can ensure your pixel code is correctly placed without needing to edit core file structures.

Remember to test your setup thoroughly and monitor your Pixel data for accurate performance insights. Happy optimizing!

Checkout Performance Themes Orders

Our network