Facebook转换像素与脚本标记与异步

时间:2014-12-18 02:16:03

标签: javascript facebook performance asynchronous

Facebook建议将以下代码添加到网页以允许转换跟踪。这是几个类似的"信标之一"我们已在我们的网站上安装。他们中的许多人正在使用" createElement"将脚本标记动态插入文档模型的方法...

<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 || [];
_fbq.push(['track','1234567890',{'value':'10.00','currency':'USD'}]);
</script>

问题,可以简化代码以使用以下脚本标记...

<script src="//connect.facebook.net/en_US/fbds.js" async></script>
<script>
   window._fbq = window._fbq || [];
   _fbq.loaded = true; // This may not even be needed anymore
   _fbq.push(['track','1234567890',{'value':'10.00','currency':'USD'}]);
</script>

0 个答案:

没有答案