Facebook Pixel Code

Hi my client want to put this pixel code on there website and in the
instructions it says to put it between the head tags but isnt it better
to put scripts before the end body tag?

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');

fbq('init', '936691883114326');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=936691883114326&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->

probably to be more reliable. If you load it last there is a higher chance it might not load correctly and give inaccurate results. Google analytics reads 20% or so wrong compared to our actual server analytics most likely from the code failing to load or being actively stopped by not having JS etc and that is at the bottom of the page.

What doesn’t make sense to me though is the <noscript> tag in the code as if a user didn’t have JS enabled it would put an image into the <head> where it shouldn’t be.

I’d probably just put it down before the end and see how it gets on.

alright

this is what my code looks like with that script last:

 </footer>
    <!-- end of footer -->

  </div>

  <!-- Google Maps -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  <script src="Scripts/dropdown_language.js"></script>
  <script src="Scripts/animate.js"></script>
  <script src="Scripts/bootstrap.min.js"></script>
  <script src="//use.typekit.net/xsr0nkz.js"></script>
  <script>
    try{Typekit.load({ async: true });}catch(e){}
  </script>
  <!-- Google Analytics -->
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  
    ga('create', 'UA-57297790-2', 'auto');
    ga('send', 'pageview');
  </script>
      <!-- Facebook Pixel Code -->
  <script>
        !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
        n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
        n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
        t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
        document,'script','https://connect.facebook.net/en_US/fbevents.js');

        fbq('init', '936691883114326');
        fbq('track', "PageView");
    </script>
    <noscript><img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=936691883114326&ev=PageView&noscript=1"
    />
    </noscript>
    <!-- End Facebook Pixel Code -->
</body>

</html>

This is from the facebook pixel troubleshooting guide.

Pixel Took Too Long to Load

This warning suggests that it took a long amount of time before the pixel was activated. This may be due to where the pixel is located on the page.

If a web page visitor closes the page, clicks on a link, or navigates away before the pixel event activates, the action will not be tracked. A significant percentage of actions and conversions can be lost due to this.

It is recommended to place the pixel code early in the web page, preferably just before the closing </head> tag in the HTML.

where the supplied HTML will be invalid?

It has to be in the body because of the image tag.

Of course the script will not run AND the noscript will not activate for browsers with antiquated JavaScript enabled but which don’t support the more modern JavaScript that the script requires to be supported but doesn’t test for…

so is it fine where I have it?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.