简体   繁体   English

Facebook像素未在我的网站上呈现

[英]Facebook pixel is not rendering on my site

I am trying to add a facebook pixel to my ruby on rails application. 我试图在我的ruby on rails应用程序中添加一个facebook像素。 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要求我将此JavaScript添加到页面的顶部-因此我将其添加到head部分的application.html.erb布局中:

<!-- 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. 然后,我使用google chrome facebook pixel tester扩展程序测试了我的网页-并不断显示找不到像素。 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! 好吧-问题是-我正在测试的页面没有使用Rails的模板进行渲染-因此该代码从未运行过! Silly but true - all fixed now. 愚蠢但真实-现在全部解决。 The code itself was absolutely fine. 代码本身是绝对好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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