Support » Plugin: GDPR » How to set up fb pixel and Google Analytics opt-out

  • Resolved darkmoonxarx


    Hi there, from what I can understand the scope of this plugin is exactly what I need, but I am a bit lost. How exactly do I build an opt-out link/button for my users that deactivates the facebook and Google scripts when clicked?
    I want to keep it opt-out until eprivacy in 2019 probably forces us to an “only opt-in” solution.
    I would appreciate any help!
    Also, is there a way to donate to the devs? I really appreciate the time and effort put into this plugin.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Is there something like a quick start guide how we can set up that the plugin actually activates and deactivates cookies?

    Plugin Author Fernando Claussen


    Hi @darkmoonxarx,

    First you need to register the consent on the plugin settings page.

    Let’s say you register a “Perfomance Tracking Consent” and you describe it as using analytic tracking solutions to monitor site usage so you can improve your services.

    This will be off by default. Users can opt-in on registration or later on through the consent management window (Using the gdpr_preferences shortcode described on the description of the plugin creates a button to open this window ).

    After registering this option, you should have your dev or yourself wrap the code with our helper function have_consent( $consent_id ) ( It was pointed out to me that this should be changed to has_consent so I will be doing an update later but this function will not stop working ).

    So for google analytics you can do something like

    <?php if ( ! have_consent( 'tracking' ) ): ?>
    		window['ga-disable-UA-XXXXXXXX-X’] = true;
    <?php endif; ?>

    For facebook pixel you could do something similar, like

    <?php if ( have_consent( 'tracking' ) ) : ?>
                   // Facebook pixel script code here.
    <?php endif; ?>


We are still setting up a way for donations to happen. I do appreciate the gesture though.

    While we don’t currently have a donation link, an honest review can help us a ton.

    I’m also preparing a documentation to help other users like you to set everything up.

    Thank you so much.

    Thanks for the fast reply!
    I have no dev so I have to figure it out myself… That name $consent_id where exactly does it come from?

    Oh and also I had problems with other cookie plugins (“EU Cookie Law” and “dfactory”) when my caching plugin WP fastest Cache is on. Do you know if caching interfers with this plugin or will it work even on cached sites?

    • This reply was modified 1 year, 10 months ago by darkmoonxarx.

    Ah, I just found it 😀 Thank you so very much for your time… I was looking under cookies, not in the consent area.

    Can I also do pre-checked consents that are not required and can be deactivated? Before ePrivacy in 2019 it is still allowed to enable anonymized Google Analytics by default in Germany, but I would like to use the GDPR’s interface for the opt-out (removing the tracking code completely when the user unchecks it).

    So “cookies” is more an information area or does it really clear cookies listed under “Cookies used by the site”?

    Hehe documentation is probably a good idea… When I finally understood everything about your plugin I will make a video tutorial about it.

    • This reply was modified 1 year, 10 months ago by darkmoonxarx.

    Hm, I am still not sure I fully got it.

    What cookies are activated, when the user clicks “I understand” on the banner? Only the required ones but also the optional ones?
    And how are theses cookies blocked or activated? I have to wrap them all by hand in the functions.php using if ( have_consent( ‘$consent’ ) ) or is_allowed_cookie( $cookie )? Or is it enough to name them in the cookie settings area of the plugin?

    Sorry to bug you with so many questions… but maybe it helps you to see your plugin from an outsider’s perspective.

    Okay I think I got it now. Unfortunately, WP Fastest Cache sometimes serves the wrong version of the page to me (deactivated GA code although I agreed to cookies, activated GA code although I switched it off). Is this something I can fix?

    1. I added “Tracking” under Settings > Cookies and wrote “_ga” as one of the “Cookies used by the site”
    2. Then I wrapped my Google Analytics in an if function using is_allowed_cookie( $cookie ) of this plugin. I use a plugin called Code Snippet to add it to my functions.php.

    function google_analytics_tracking_code(){
    	$propertyID = 'UA-XXXXX-X'; // GA Property ID
    	if ( function_exists('is_allowed_cookie') && is_allowed_cookie( '_ga' ) ) { ?>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="<?php echo $propertyID; ?>"></script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', '<?php echo $propertyID; ?>', { 'anonymize_ip': true });
    // Google Analytics Snippet ends here
    <?php }
    add_action('wp_head', 'google_analytics_tracking_code');
    Plugin Author Fernando Claussen


    Hi @darkmoonxarx,

    I’m glad you are figuring things out.
    I wish there was a way to completely block cookies without a dev to use those functions but that is not possible afaik. Well.. that’s not entirely true either. If the cookies is being created by one of the plugins or your theme through a PHP function, we can block it (please let me know if this is not working). The real problem are cookies that get created through javascript. I could not find a way to block the creation of these without a wrapper function.

    For GA in particular, you don’t need to wrap the entire code block, you can just add window['ga-disable-UA-XXXXXXXX-X’] = true; and this will stop GA from sending data to their servers.

    When clicking I accept on the cookie bar, it sets the required cookies but not optional cookies. We can’t enable any optional stuff without explicit and clear consent.

    I did not plan to have fields enabled by default and users disabling it because that’s against GDPR.

    Ah, that’s the disable cookie, I see. Smart… Thanks for the tip and your patient help!

    I think using the wrapper function for JavaScript code will be doable for everyone once a step by step instruction is available

    But right now if I click “I understand” in the cookie bar the script above gets activated when I refresh the page or navigate to the next one… that is the intended behavior or is it not?

    Any idea what I can do so it works with WP Fastest Cache enabled?

    Plugin Author Fernando Claussen


    Hi @darkmoonxarx

    I already replied to another ticket, but here goes.

    I need to further investigate this issue with caching plugins. Need to figure a way to whitelist it.

    I added a task to GitHub for this. You will see an update about this as soon as I figure a way around it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to set up fb pixel and Google Analytics opt-out’ is closed to new replies.