Support » Plugin: W3 Total Cache » GDPR and W3 Total Cache

  • mic85b


    I have installed GDPR plugin and it works great. But not with W3 Total Cache. The problem is that disabling cookies code is hard coded into page-cache.

    Is it possible to have page cache still turned on but exlude some pice of code of being cached and will be dynamic genartation?

    I have added to functions.php this code which adding small addon for this users who would like to have disabled Google Analitics cookie. If somone will change his setting and agree for this cookies then this small part of code won’t be added to page. So this part of page will be dynamics and shound’t be cached.

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

    • This topic was modified 12 months ago by  mic85b.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Fist Full of Crisco


    You’d want to make use of fragment caching with disk:basic mode. in short, you’d add a commented out tag using m_func around the code that u want inserted. When the cache is loaded w3tc will pull the cache and check that piece of php code to decide if it should insert that script.

    Plugin Support gidomanders


    Conditional loading of scripts should actually be done using JavaScript. There should be a check for the cookie in JavaScript so you can wrap the initialization of Google Analytics in an if (cookiesAllowed()) { setGA() }. That makes it all a lot easier, especially the caching.

    We’re updating the FAQ for more details.

    Plugin Support Marko Vasiljevic


    Hello @mic85b,

    Have you managed to resolve the issue? Please give us a feedback so you can close the topic and mark it as resolved.

    Best regards,


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘GDPR and W3 Total Cache’ is closed to new replies.