如何在网站中为Facebook像素创建选择退出选项?

Sha*_* Sh 5 facebook facebook-pixel

**我在寻找:**我正在寻找的是,如何限制我网站上的facebook像素来跟踪并将我的网站用户信息发送到Facebook.

我已经知道的: Facebook像素跟踪用户的数据,如谷歌标签.但Google提供了一个脚本,允许用户选择此选项,这意味着将跟踪用户的信息,但不会将其发送给Google.

以下是google(来源)提供的退出选项代码:

<script>
// Set to the same value as the web property used on the site
var gaProperty = 'UA-XXXX-Y';

// Disable tracking if the opt-out cookie exists.
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}

// Opt-out function
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
}
</script>
Run Code Online (Sandbox Code Playgroud)

现在我想为我的facebook像素提供类似的选项,因此用户可以禁用Facebook上的数据跟踪.我实际使用的是facebook提供的代码,用于跟踪我网站上特定事件的信息.这是我现在使用的代码(来源):

<!-- 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');
// Insert Your Facebook Pixel ID below. 
fbq('init', 'FB_PIXEL_ID');
fbq('track', 'PageView');
</script>
<!-- Insert Your Facebook Pixel ID below. --> 
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=FB_PIXEL_ID&amp;ev=PageView&amp;noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
Run Code Online (Sandbox Code Playgroud)

fur*_*ceX 3

我创建了一个选择退出系统,结合现有的许多代码源,选择退出 GA 和 FB 跟踪。我在这里发布了详细信息:https ://stackoverflow.com/a/51217955/3817964

我不仅想从 GA 和 FB 中删除开发者跟踪,而且还希望公司内部的一些人不被计入 GA 和 FB。因此,我想要一种相对简单的方法,让这些人在没有插件的情况下将自己排除在分析之外,或者排除域 IP(就像那些拥有笔记本电脑的人闲逛一样)。

创建了一个网页,用户可以访问该网页并单击链接以选择退出 GA 和 FB 跟踪。它为网站放置一个 cookie。然后我检查该 cookie 以确定我们是否应该向 GA 和 FB 发送数据。