0
votes

I need to add Facebook tracking code to a specific page in Drupal 7. I was wondering if there was a way to add the code to the html.tpl.php file where there is some code that calls for it to be added to a specific page.

I tried adding the code to a block which would live on the page, but the code is being stripped out (disable rich text, add code and save)

This is the code I am trying to add

  <!-- Facebook Conversion Code for Ecuador landing page leads -->
    <script>(function() {
      var _fbq = window._fbq || (window._fbq = []);
      if (!_fbq.loaded) {
        var fbds = document.createElement('script');
        fbds.async = true;
        fbds.src = '//connect.facebook.net/en_US/fbds.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(fbds, s);
        _fbq.loaded = true;
      }
    })();
    window._fbq = window._fbq || [];
    window._fbq.push(['track', '6026961635755', {'value':'0.00','currency':'USD'}]);
    </script>
    <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6026961635755&amp;cd[value]=0.00&amp;cd[currency]=USD&amp;noscript=1" /></noscript>

After I save it this is what I am getting

<!-- Facebook Conversion Code for Ecuador landing page leads --><noscript>&lt;img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6026961635755&amp;amp;cd[value]=0.00&amp;amp;cd[currency]=USD&amp;amp;noscript=1" /&gt;</noscript>
2
have you tried making the body of the block to full html - Viswanath Polaki

2 Answers

2
votes

Facebook Tracking Pixel module provides an easy to use interface that enables you to include the conversion code to the page(s) you select.

It applies the 'new' Facebook pixel code, the one that Facebook recommends using.

Drupal project page: https://www.drupal.org/project/facebook_tracking_pixel

0
votes

When you create a static block for text format (drop-down bellow body field) select "plain text" so drupal shouldn't filter out some tags. Under visibility settings you can specify on what pages this block should be shown. For more powerful mechanism for specifying on what page to display the block look for "context" module.