Support » Plugin: GDPR » Disable Google Analytics

  • Resolved zissis

    (@zissis)


    Hello i’ve used your function:

    add_action( 'wp_head', 'my_google_opt_out' );
    function my_google_opt_out() {
      if ( ! is_allowed_cookie( '_ga' ) ) {
        ?>
        <script>
           window['ga-disable-UA-xxxxxxx-x'] = true;
        </script>
        <?php
      }
    }

    But it disable’s Google analytics Cookies even if i allow the “_ga, _gid, _gat” Cookie section.

    • This topic was modified 1 year ago by  zissis.
    • This topic was modified 1 year ago by  zissis.
Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Fernando Claussen

    (@fclaussen)

    This is an implementation problem.

    I would need access to your installations to figure out what is wrong.

    Btw, do you have a caching plugin or server cache installed?
    If so, your site is serving a cached version of the page, where the cookies were not allowed.

    If that’s the case, I would do it the javascript way instead.

    John Hogan

    (@poegle1987)

    I had problems initially with my setup as I had GA block running in a theme options text box (Genesis Theme Options in my case). Moving the GA block to run in functions.php then worked. Rather than just dumping the block on the documentation I put it into the main GA block like this:

    Note: My GA doesn’t use the same cookies as you have listed instead inserts _utma etc, so replace with your cookies and your GA ID:

    function google_analytics_tracking_code(){
    	if ( is_allowed_cookie( '_utma' ) ){
      ?>
    
    	<script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
      _gaq.push(['_trackPageview']);
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    </script>
    
    <?php }
    }
    
    add_action('wp_footer', 'google_analytics_tracking_code');
    • This reply was modified 1 year ago by  John Hogan.
    zissis

    (@zissis)

    Yeah I am using cache. This is the code for the JS that i should run right? If so it doesnt work with that either.

    if ( ! is_allowed_cookie( '_ga' ) ) {
         window['ga-disable-UA-xxxxxxx-x'] = true;
    }
    morpheus101

    (@morpheus101)

    I have a similar problem and have autoptimize and w3totalcache installed. I am running the code as in the first post and although it works, it won’t update when I toggle the cookie on and off. Can anyone let me know the correct way to implement this the javascript way?

    Thanks

    morpheus101

    (@morpheus101)

    After a bit more testing it seems to only happen when logged out. When logged in, the cookie on/off toggle works as it should

    imloic

    (@imloic)

    It’s work with admin login ?

    morpheus101

    (@morpheus101)

    yes, works with admin login but with another user it says “we could not verify the security token. Please try again”.

    morpheus101

    (@morpheus101)

    The “we could not verify the security token. Please try again” only happens on mobile device which is a known sporadic bug afaik. Works fine on pc

    Plugin Author Fernando Claussen

    (@fclaussen)

    The reason why it happens to offline users is that caching is disabled for admins most of the time.

    About the security token issue, it happens for desktop too. It’s a random error that can be caused by several reasons. I’m releasing v2 today(finally) and that should fix the issue by making the requests work with ajax.

    morpheus101

    (@morpheus101)

    Hi Fernando, That is what I thought. Could you please share how I could bypass the caching issue by using the Javascript code and will this solve the issue?

    Looking forward to V2. Thanks again for this great plugin. It has helped me a lot in getting ready for the GDPR!!

    imloic

    (@imloic)

    it can be a problem if I use the plugin: Google Analytics Dashboard for WP (GADWP) ?

    morpheus101

    (@morpheus101)

    Hi Imloic. I removed the GADWP as I had issues with not beeing able to control the cookies. I now inject the GA code with the cookie allowed check straight into my header section:

    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXX-X"></script>
    <script>
      if (is_allowed_cookie('_ga')) {
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());gtag('config', 'UA-XXXX-X', {"anonymize_ip":true,"allow_display_features":false,"link_attribution":false});
      }
    </script>

    I know it is a caching issue. Just need to find a solution as I do not want to remove my caching plugins 😉

    imloic

    (@imloic)

    Thanks morpheus101

    i try you script and remove GADWP.
    _ga etc. is always load even if i desactivate in privacy preferences

    morpheus101

    (@morpheus101)

    @imloic

    Does this also happen when logged in as admin?. Do you use a caching plugin?

    imloic

    (@imloic)

    no cache plugin and connected in admin profile. Maybe before desactivate GADWP Maybe I should have cleared the plugin cache of it.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Disable Google Analytics’ is closed to new replies.