• Hi,
    I’m working on a cookie consent plugin for WordPress (for my employer), and they requested that I make support for your plugin since a lot of our customers are WooCommerce webshops using this plugin to send data to their GA4.
    The cookie plugin changes consent state using ajax, when user clicks on any of the consent buttons in the cookie popup window. As of right now our cookie plugin are not using a cookie scanner, but instead the tracking scripts are saved in the plugin options, and then added to head/body elements upon consent.
    I found the filter woocommerce_ga_disable_tracking, but I have experienced a few problems. However I’m unsure if the problem lies with my implementation.

    The code below, shows what I have done to disable tracking until consent. The function is in a separate file located in my plugin’s functions folder.

    <?php
    
    add_filter( 'woocommerce_ga_disable_tracking', 'cookie_care_woocommerce_ga_compatibility', 20 );
    
    function cookie_care_woocommerce_ga_compatibility( $disable_tracking ) {
    
    ? ? // cookie name, to make code easier readable
    ? ? $cookie_name = 'cookie-care-consent';
    
    ? ? if ( class_exists( 'WC_Google_Analytics' ) && class_exists( 'Cookie_Care_Settings' ) ) {
    
    ? ?     // return true for disabling tracking, return false for not disabling tracking
    ? ? ? ? $disable_tracking = ( isset( $_COOKIE[ $cookie_name ] ) && $_COOKIE[ $cookie_name ] === 'necessary_analytics' || $_COOKIE[ $cookie_name ] === 'necessary_marketing_analytics' ) ? false : true;
    
    ? ? }
    
    ? ? // always return disable tracking, even if it has not been modified.
    ? ? return $disable_tracking;
    }

    The problems I experience is that sometimes, either the _ga, the _ga_{ID} or both cookie(s) will exist before user consent or when the cookie-care-consent value does not include ‘analytics’. And I have checked the $disable_tracking using error_log(), which shows the correct value depending on the consent.
    Also when changing consent from no consent it requires a page reload (actually two page reloads) before being able to see the google analytics cookies in the developer console window.

    Am I doing something completely wrong, lacking functionality or is there something else wrong?

Viewing 6 replies - 1 through 6 (of 6 total)
  • David

    (@dlim_vernier)

    I’m also dealing with this same problem where we’re interested in using this plugin, but since I can’t disable cookies until cookie consent is given (custom integration), I can’t use this plugin.

    I tried the filter you’ve found ‘woocommerce_ga_disable_tracking’ and still had cookies loaded. It may be that the ecommerce tracking is no longer tracked, but the cookies are still loaded.

    I also saw a load_opt_out() static function in class-wc-abstract-google-analytics-js.php and tried that code as well. But three cookies are still loaded without consent.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @joped,

    Looking at your code, it looks like you’re on the right track with the woocommerce_ga_disable_tracking filter. However, a few things could be causing the issues you’re experiencing.

    1. Timing: The filter may be applied after the Google Analytics script has already been loaded. This could be why you’re seeing cookies before the user has given consent. You might need to check the execution order of your scripts.
    2. Page Reloads: It’s normal to require a page reload for the changes to take effect. This is because the Google Analytics script is loaded when the page is initially loaded, and any changes to the cookies won’t apply until the next page loads.
    3. Cookie Existence: The _ga and _ga_{ID} cookies are set by Google Analytics, not by the WooCommerce Google Analytics Integration plugin. Therefore, these cookies might be set by other scripts on your site or by Google Analytics itself if it’s been loaded elsewhere on your site.

    Hi @dlim_vernier,

    The load_opt_out() function intended to provide an opt-out for users who have already given consent. It’s not designed to prevent the initial loading of cookies.

    Please note that these particular forums are meant for general support with the core functionality of WooCommerce Google Analytics Integration itself. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question.

    I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.

    @dlim_vernier, I’m kind of relived to not be the only one struggling with this.

    @shameemreza thank you for that explaination, I will look into this. The site is using Goolge Tag Manager that is coupled together with Google Analytics.

    Hi there @joped ??

    I will look into this. The site is using Goolge Tag Manager that is coupled together with Google Analytics.

    That’s great to hear! Please let us know how it goes. We’re happy to help, so please feel free to reach out to us again if you have any other questions.

    @anastas10s I will let you know what I find out. However just looking at the response from @shameemreza makes me think that the problem might be with our setup of google tag manager.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @joped,

    Yes, the issue may lies with your setup. Google Tag Manager and Google Analytics work together, but if not set up correctly, it can cause problems like the one you’re experiencing.

    Please feel free to ask if you have any more questions or need further assistance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Cookie consent plugin block scripts until consent’ is closed to new replies.