I need to add a Custom Audience Pixel Code for Facebook into my Magento site. The instructions say to paste this inbetween the tags, which is simple with basic websites but a lot more complex with Magento.

Any idea where to add this?

3 Answers 3


It depends upon what do you want to achieve, there are several ways you can do it in Magento. Either you can create a custom module or copy paste the given pixel tracking code in head.phtml or footer.phtml. Both these methods will install your custom audience pixel tracking on your Magento site.

If you chose latter, just make sure you add this in your custom theme instead of base theme because base theme will be overwritten with your next Magento upgrade.

But bear in mind that custom facebook audience pixel tracking does come with standard and custom events which is far more work than adding pixel tracking code in head or footer section of your Magento site. For more information regarding these events use the following link


And if you are interested in implementing all the events, the below module can help you achieve this on your Magento store -:


Hope it helps

Cheers S


I would make a module - let's say Yourcompany_FbCode

app/code/local/Yourcompany/FbCode/etc/config.xml :

<?xml version="1.0"?>

app/design/frontend/base/default/layout/yourcompany_fbcode.xml :

<layout version="1.0.0">
        <reference name="before_body_end">
            <block type="core/template" name="fbpixel.block" after="-" template="yourcompany/fbcode/fbpixel.phtml">
                <action method="setCacheLifetime"><s>0</s></action>

app/design/frontend/base/default/template/yourcompany/fbcode/fbpixel.phtml :

(Your fb pixel code goes in here - this is the example code from fb)

<!-- Custom Audience Pixel Code -->
    // Insert Your Custom Audience Pixel ID below.
    fbq('init', '<FB_PIXEL_ID>');
    fbq('track', 'PageView');
<!-- Insert Your Custom Audience Pixel ID below. -->
<noscript><img height="1" width="1" style="display:none"
<!-- End Custom Audience Pixel Code -->

app/etc/modules/Yourcompany_FbCode.xml :

<?xml version="1.0"?>

app/code/local/Yourcompany/FbCode/Helper/Data.php :


class Yourcompany_FbCode_Helper_Data extends Mage_Core_Helper_Abstract {


And that's it - your pixel will be inserted into every page on the site, at the bottom to help with loading speed.

  • how about just adding it to a custom page/html/footer.phtml ?
    – paj
    Commented Aug 31, 2015 at 8:21
  • What about adding this code to "Miscellaneous Scripts" in the admin panel system->Configuration->Design->HTML Head. Isn't it a good practice?
    – Mujahidh
    Commented Mar 10, 2016 at 9:02

I added the same code code to "Miscellaneous Scripts" in the admin panel system->Configuration->Design->HTML Head. I add this as an answer if some one can see this and explain is it a good practice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.