无法弄清楚为什么动态添加Facebook跟踪不会触发与硬编码的trackID相反的跟踪。
//works fine and I can see 2 tracking pixels with FB pixel helper
fbq('init', "123456");
fbq('init', "789789");
从数组添加时将无法正常工作
var trackingIds = ["123456", "789789"];
trackingIds.forEach(function(i){
fbq('init', i);
});
完整代码
<!-- 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');
var SMMdata = (JSON.parse({{CMS social management - tracking data}}));
console.dir(SMMdata["Facebook"]);
if(typeof SMMdata["Facebook"] !== "undefined"){
SMMdata["Facebook"].forEach(function(i){
fbq('init', i);
});
}
fbq('track', 'PageView');
</script>