简体   繁体   中英

Facebook pixel is not rendering on my site

I am trying to add a facebook pixel to my ruby on rails application. Facebook asked me to add this javascript to the head of my page - so I added it to the application.html.erb layout in the head section:

<!-- Facebook pixel -->
<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;
}
_fbq.push(['addPixelId', 'thisismysecretid']);
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'PixelInitialized', {}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=938407189542791&amp;ev=PixelInitialized" /></noscript>

Then I tested my pages by using the google chrome facebook pixel tester extension - and it continually says no pixel was found. When I look at the generated source from my application - i actually don't see any of this inside the head of the page, so I assume that's why its not working - but why isnt it being rendered or processed?

SO! Why?! What am I doing wrong? Many thanks for all your support.

Well - the problem was - the page I was testing this on was not being rendered using templates from rails - so this code was never being run! Silly but true - all fixed now. The code itself was absolutely fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM