我用 AngularJS 构建了单页应用程序。我想使用 Facebook Pixel 跟踪 pageView 这个网络应用程序。但在分析板上,Facebook Pixel 会忽略“#”后面的 url 部分。 在此图像中,每个 URL 显示在 http://localhost/ 中。
我可以推送自定义 pageView(删除 #)来解决此问题吗?
最佳答案
对于我的情况,它适用于以下配置:
- 在index.html中添加带有跟踪ID的fb像素代码
<!-- 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');
fbq('init', '<<PIXEL ID>>'); // Insert your pixel ID here.
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=133095247279894&ev=PageView&noscript=1"
/></noscript>
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->
在状态 Controller 上注入(inject) $window
// Registration angular.module('app.module') .controller('LeadsController', ['$scope', '$state', '$window']); $window.fbq('track', 'InitiateCheckout'); //or Purchase/Leads/CompleteRegistration event
它是这样工作的,因为基本上 fbq 已经绑定(bind)在窗口对象上。 希望这有帮助!
关于javascript - 带有单页应用程序的 Facebook Pixel(Angularjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34020526/