在jQuery中转换Facebook像素代码

时间:2016-06-28 00:49:33

标签: jquery facebook tracking

是否有人已将facebook pixel tracking code转换为jQuery函数?

我尝试将其与$.getScript一起使用,但之后跟踪无效:(

! 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.src = v;
  s = b.getElementsByTagName(e)[0];
  s.parentNode.insertBefore(t, s)
}(window, document, 'script', 'https://connect.facebook.net/de_DE/fbevents.js');

1 个答案:

答案 0 :(得分:0)

未经测试......:)

<script>
jQuery(document).ready(
function($)
{
  if(! window.fbq)
  {
    n = window.fbq = function ()
    {
      n.callMethod ?
      n.callMethod.apply(n, arguments) : n.queue.push(arguments)
    };

    if (!window._fbq) window._fbq = n;
    n.push = n;
    n.loaded = !0;
    n.version = '2.0';
    n.queue = [];

    $.getScript('https://connect.facebook.net/de_DE/fbevents.js', 
    function()
    {
      console.log('facebook pixel loaded... do your thing');
    });
  }
});
</script>