• Resolved Daniel P.

    (@danidub)


    Hello, we use a GDPR plugin to let the user decide if using cookies or not.

    Does you plugin have some hook or action for us to use and activate the google scripts or not? (based on some user action)

    For example with other plugins we use something like:

    /* disable Google Analytics on gdpr_cookie plugin */
    add_filter('woocommerce_ga_disable_tracking', 'gdpr_ga_integration_wc', 20);
    function gdpr_ga_integration_wc($disable_ga_wc)
    {
        if (function_exists('gdpr_cookie_is_accepted')) :
            if (!gdpr_cookie_is_accepted('thirdparty')) :
                $disable_ga_wc = true;
            endif;
        endif;
        return $disable_ga_wc;
    }
    add_action('gdpr_force_reload', '__return_true');

    In this example the plugin we are blocking is the WooCommerce Google Analytics Integration and has one filter we can hook and enable or disable the plugin: add_filter('woocommerce_ga_disable_tracking', 'gdpr_ga_integration_wc', 20);

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support James Osborne

    (@jamesosborne)

    Hi Daniel,

    Thanks for reaching out. There is a filter than can be used to ensure Site Kit doesn’t place a Google Analytics snippet in various circumstances. The filter is below:
    add_filter( 'googlesitekit_analytics_tag_blocked', '__return_true' );

    For the Google Analytics 4 snippet, if placed via Site Kit, you can use googlesitekit_analytics-4_tag_blocked.

    You can apply this to your own custom functions if you wish.

    For consent-type blocking specifically, you can use an alternate filter which will still output the tags, but in an initially disabled state.

    add_filter( 'googlesitekit_analytics_tag_block_on_consent', '__return_true' );

    The above applies to Universal Analytics. You can replace the analytics reference above with analytics-4 (for GA4), adsense for the AdSense module or tagmanager for Google Tag Manager.

    Note that if you’re an AMP user the filters to be applied differ slightly. Let me know if so.

    There is also a mini API that can be used by cookie consent type plugins.

    Let me know if you have any questions with the above.

    Thread Starter Daniel P.

    (@danidub)

    Great @jamesosborne

    I will make some tests and return if any problem detected. Marking as solved for now!

    Thank you.

    Plugin Support James Osborne

    (@jamesosborne)

    No problem, happy to help! Best of luck.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Disable scripts based on user cookie selection’ is closed to new replies.