Support » Plugin: GDPR » W3 Totalal Cache problem

  • Resolved mic85b

    (@mic85b)


    Your plugin works great but I have a problem when it works with W3 Total Cache. The problem is that code which is disabling some cookie is permanently-cached. How can I solve this problem. Without caching my website works very slow 🙁

    I have added this function to functions.php

    add_action( ‘wp_head’, ‘my_google_opt_out’ );
    function my_google_opt_out() {
    if ( ! has_consent( ‘analytics’ ) || ! is_allowed_cookie( ‘_ga’ ) ) {
    ?>
    <script>
    window[‘ga-disable-UA-XXXXXXXX-X’] = true; // Don’t forget to replace X for your actual UA numbers.
    </script>
    <?php
    }
    }

Viewing 8 replies - 1 through 8 (of 8 total)
  • mic85b

    (@mic85b)

    I have been looking for answer and it seems that it is problem.

    First of all I can disable full page cache. But the result is slowing down page. Anwer time on my server is not 300-400ms but now over 1-1,5 second. So it is big problem becouse site performance is bad.

    Second possiblity: partial caching is with W3 Total Cache possibile but in pro version, only.

    Maybe there is possible to block cookies by other method (AJAX)? Could You give me some advice/instruction how to do it?

    Thank You

    • This reply was modified 1 year ago by  mic85b.
    Bonaldi

    (@bonaldi)

    Hi @mic85b,
    Did you customize this javascript script?
    Can you give us a link to your site to check?
    Regards.

    mic85b

    (@mic85b)

    Finally I have tried to do it by javascript. I don’t know why but it doeasn’t work. In my opinion it SHOULD. Where is a bug? Maybe somone will help.

    In this code is some kind of simplificatin: it shouldn’t check if string of cookie contains “_ga”. It should build full array of allowed cookies and check if “_ga” is in array. But I am not an expert and it is difficult for me to do it in correct way. But to test it SHOULD work but it doeasn’t work. Please help 🙂

    ==============Generated Cookie==============
    gdpr[allowed_cookies]

    When additional cookies accepted
    %5B%22gdpr%22%2C%22wordpress_test_cookie%22%2C%22_ga%22%2C%22_gid%22%2C%22_gat%22%2C%22_gat_gtag_%22%5D

    When additional cookies ARE not accepted
    %5B%22gdpr%22%2C%22wordpress_test_cookie%22%5D

    ===============GA Code===============
    <!– Global site tag (gtag.js) – Google Analytics –>
    <script async src=”https://www.googletagmanager.com/gtag/js?id=UA-UA-xxxxxx-x”></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());

    gtag(‘config’, ‘UA-xxxxxx-x’);
    </script>

    ===============My javascript addon to put in header, below GA code===============
    <script>
    var x = getCookie(‘gdpr[allowed_cookies]’);

    if (x.indexOf(“_ga”) >= 0)
    {
    // document.write(“We use GA”);
    window[‘ga-disable-UA-xxxxxx-x’] = false;
    }
    else
    {
    //document.write( ‘We do not use GA’ );
    window[‘ga-disable-UA-xxxxxx-x’] = true;
    }

    function getCookie(name) {
    var nameEQ = name + “=”;
    var ca = document.cookie.split(‘;’);
    for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==’ ‘) c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }
    </script>
    =================================

    • This reply was modified 1 year ago by  mic85b.
    mic85b

    (@mic85b)

    I have added one line (stronged) and works great with W3 Total Cache 🙂 But still it shouldn’t check if string of cookie contains “_ga”. It should build full array of allowed cookies and check if “_ga” is in array.

    Maybe somone will correct it.

    ===================================
    <script>
    var x = getCookie(‘gdpr[allowed_cookies]’);

    if (x == null){
    var x = “”;
    }

    if (x.indexOf(“_ga”) >= 0)
    {
    // document.write(“We use GA”);
    window[‘ga-disable-UA-xxxxxx-x’] = false;
    }
    else
    {
    //document.write( ‘We do not use GA’ );
    window[‘ga-disable-UA-xxxxxx-x’] = true;
    }

    function getCookie(name) {
    var nameEQ = name + “=”;
    var ca = document.cookie.split(‘;’);
    for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==’ ‘) c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }
    </script>

    • This reply was modified 1 year ago by  mic85b.
    mic85b

    (@mic85b)

    Now reads cookies from array correctly.

    ===========================
    <script>
    var x = getCookie(‘gdpr[allowed_cookies]’);

    if (x == null){
    var x = “”;
    }

    if (isInArray(x, “_gid”))
    {
    // document.write(“We use GA”);
    window[‘ga-disable-UA-xxxxxx-x’] = false;
    }
    else
    {
    //document.write( ‘We do not use GA’ );
    window[‘ga-disable-UA-xxxxxx-x’] = true;
    }

    function getCookie(name) {
    var nameEQ = name + “=”;
    var ca = document.cookie.split(‘;’);
    for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==’ ‘) c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }

    function isInArray(array, element) {
    return array.indexOf(element.toLowerCase()) > -1;
    }

    </script>

    • This reply was modified 1 year ago by  mic85b.
    Plugin Author Fernando Claussen

    (@fclaussen)

    Why go through all that trouble if we provide a Javascript function to check for a cookie?

    You could have done is_allowed_cookie( '_ga' ) or window.is_allowed_cookie( ‘_ga’ )` would also work.

    This function is available both in PHP and JS

    But I’m glad you got it working.

    mic85b

    (@mic85b)

    Right, it much more easy 🙂

    <script>
    if (!window.is_allowed_cookie( ‘_ga’ ) )
    {
    window[‘ga-disable-UA-xxxxxxx-xxx’] = true;
    }
    </script>

    • This reply was modified 1 year ago by  mic85b.
    dougeth

    (@dougeth)

    Where did you place

    <script>
    if (!window.is_allowed_cookie( ‘_ga’ ) )
    {
    window[‘ga-disable-UA-xxxxxxx-xxx’] = true;
    }
    </script>

    To make it work with W3 Total Cache

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘W3 Totalal Cache problem’ is closed to new replies.