GDPR – Google Opt-out + Facebook Pixel Opt-out

According to the current status, users must be offered an opt-out option for Google Analytics. A few thoughts on the technical implementation

According to our information (as of May 2020), no pure opt-out option is permitted for such tracking; instead, prior user consent (opt-in) is required before activating such tracking codes.


See also 2022/FB PIXEL collects disease data:

The whole discussion about tracking with Analytics & Co in the context of the new data protection rules should not be discussed here. Many things are still unclear and disputed (and will change again with the planned ePrivacy Directive) but the prevailing opinion seems to be that under certain conditions Goolge Analytics and Facebook “pixel” conversion tracking MOMENTAN even after 25.5. 2018 is still permitted, provided that an opt-out option is offered in the privacy statements. This is only about the opt-out codes on the website (no guarantee):

Google Analytics

Here is the code as recommended by Google:

1. code

Paste the following script over the Google Analytics script (applies to all pages):

var gaProperty = 'UA-XXXXXXXXXX-X'; //auf korrekte ID achten!!!!

var disableStr = 'ga-disable-' + gaProperty;

if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;

function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;

2. link

Copy the following code in your privacy policy to where you want the user to opt-out of Google Analytics:

<a onclick="alert('Google Analytics wurde deaktiviert');" href="javascript:gaOptout()">Google Analytics deaktivieren</a>

ProcessWire developers can easily import the link into a Hanna-Code ShortCode:


Facebook “Pixel” Tracking

For us, suitable suggestions to suppress Facebook Pixel, we have not found on the web so far. We are considering building such a code analogous to the Analytics code above. If an opt-out cookie is found, the Facebook code is simply not loaded. A page refresh (or change to another page) is then still necessary for this to run. It’s certainly not elegant. But first a solution until something better comes. In the browser console you can see what the code does.

The code is only roughly tested, we don’t have a use case at the moment (Facebook Pixel tracking is not used by us or our customers). So feedback is welcome to improve this code even more. Conceivable would be the alternative use of HTML5 browser databases or additionally of sessions (if a user generally forbids cookies).

DISCLAIMER: This is not legal advice. Whether the code really meets the requirements of the GDPR must now be shown by practice – and smart lawyers.

Comments and suggestions for improvement welcome to

Of course we would be happy about a backlink.

1. code

Insert the following script in the source code where you have your entire tracking code, e.g. at the Analytics code (applies to all pages):

// Facebook Pixel mit Datenschutz OPT OUT per Cookie (analog zu Analytics)
var fp_disableStr = 'fb-pixel-is-disabled';

if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[fp_disableStr] = true;
console.log("Facebook-Pixel ist deaktiviert - Cookie erkannt");

} else {

// kein Cookie gefunden Facebook Code laden;
// Achtung, unten den korrekten Pixel-Code einsetzen!!!!
// --------------------------------------------------------------------

fbq('init', 'XXXXXXXXXXXXXXXXXXXXX'); // Insert your pixel ID here.
fbq('track', 'PageView');

// --------------------------------------------------------------------
console.log("Facebook-Pixel Code geladen");

function fpOptout() {
document.cookie = fp_disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[fp_disableStr] = true;
console.log("Facebook-Pixel ist jetzt deaktiviert - Page Refresh nötig");

2. link

Copy the following code in your privacy policy to where you want the user to opt-out of Facebook Pixel:

<a onclick="alert('Die Facebook-Pixel-Funktionen wurden deaktiviert - Die Seite neu laden');" href="javascript:fpOptout()">Facebook-Pixel-Funktionen deaktivieren</a>

ProcessWire developers can easily import the link into a Hanna-Code ShortCode:



So, ironically, cookie technology is used here to remember the opt-out. Cookies? There was something, wasn’t there?

So the very cautious user who has cookies completely turned off will not benefit. However, this careful user will usually use browser plug-ins like “noscript” or “uBlock Origin” (or suitable ad blockers on iOS), which completely suppress all this tracking stuff anyway.

Much better than Javascript and browser plug-ins would be, you could already set in the browser, what you want to track and what not. We are convinced that this is where the journey will take us in the long term.

DISCLAIMER: The TBA-Berlin is not a law firm. The content provided here is for general information purposes only and does not constitute legal advice. We recommend that you seek independent legal advice before taking or refraining from taking any action based on the content provided here.

TBA-Berlin makes no representations or warranties, express or implied, as to the accuracy, adequacy, validity, reliability, availability or completeness of the information referenced herein. Your use or reliance on any information contained herein is for your personal use and solely at your own risk.


More news

Domain Renewal Reminder” e-mail

Sometimes domain owners receive reminder emails in English that their domain will expire if they do not respond. You can safely ignore such emails with us: With the German providers we use, domains are renewed automatically (until cancellation).

Continue reading »