please take 2 minutes of your time and take a short look at my short script. The Idea is to build a opt-out and opt-in button for my Facebook Pixel (the button will be in the privacy policy). I already build my Opt-Out function but I stuggle with a opt-in - any ideas?
Here is my script for opt-out:
// Facebook Pixel with OPT OUT via Cookie
var fp_disableStr = 'fb-pixel-is-disabled';
if (document.cookie.indexOf(fp_disableStr + '=true') > -1) {
window[fp_disableStr] = true;
console.log("Facebook-Pixel is disabled - found Cookie");
} else {
if (navigator.doNotTrack !== '1') {
// no Cookie found, load Facebook Pixel
// Now comes the Facebook Pixel
// --------------------------------------------------------------------
!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'); // Deine FB Pixel ID
fbq('track', 'PageView');
// --------------------------------------------------------------------
console.log("Facebook-Pixel Code loaded");
}
}
function fbOptout() {
document.cookie = fp_disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[fp_disableStr] = true;
console.log("Facebook-Pixel is now disabled - refresh your page");
location.reload();
}
<a onclick="alert('Facebook Pixel got disabled');" href="javascript:fbOptout()">Facebook Pixel Opt-Out</a>
Aucun commentaire:
Enregistrer un commentaire