gpt4 book ai didi

tracking - 在本地主机和开发服务器上停止 Facebook 像素跟踪

转载 作者:行者123 更新时间:2023-12-05 08:41:08 24 4
gpt4 key购买 nike

我正在使用 Facebook Pixel 在我的网站上进行跟踪。

<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', 'xxxxxxxxxxxxx');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=320956065128864&ev=PageView&noscript=1"
/></noscript>

是否有任何停止或过滤的解决方案,如 GA 过滤器排除域或 IP?谢谢。

最佳答案

添加 FB 像素的代码片段首先通过检查变量 fbq 来检查是否已经添加了 FB 像素:

if(f.fbq)return;

因此,从初始注入(inject)中跳过 FB 像素脚本的最简单方法是在 FB snipet 之前定义 fbq 变量。

<script>
const list = ['localhost'];
if (list.includes(window.location.hostname)) {
window.fbq = function() {};
}
// ...original Facebook Pixel code here
</script>

将任何域添加到list 数组以阻止 FB 像素执行。

关于tracking - 在本地主机和开发服务器上停止 Facebook 像素跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52072611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com