• Resolved Daniel P.

    (@danidub)


    Hello, as you already know in the EU (GDPR) and USA (CCPA) we need to let the user accept the cookies for using them locally. The law also says that the user must have the option to block third party cookies (as yours).

    What would be the way to block cookies until the user accepts cookies?

    Another plugins like WooCommerce Google Analytics Integration and Facebook for WooCommerce have hooks to enable or disable.

    Maybe your plugin can have something similar, a filter that if returned true the files that load the cookies are disabled and if returned false, load scripts and cookies.

    Here are some examples for those plugins using a plugin GDPR Cookie Compliance (CCPA ready)

    
    /* disable Facebook cookies on gdpr_cookie plugin */
    add_filter('facebook_for_woocommerce_integration_pixel_enabled', 'gdpr_cookie_facebook_wc', 20);
    function gdpr_cookie_facebook_wc()
    {
        $enable_fb_wc = true;
        if (function_exists('gdpr_cookie_is_accepted')) :
            $enable_fb_wc = gdpr_cookie_is_accepted('thirdparty');
        endif;
        return $enable_fb_wc;
    }
    add_action('gdpr_force_reload', '__return_true');
    
    /* 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');

    Let me know your thoughts.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Daniel P.

    (@danidub)

    Hello, after talking with other plugins as GDPR Cookie Compliance (CCPA ready) they told me that you need to include in such way any hook for disabling the cookies.

    So other cookie plugins and developers can block or allow (by previous user acceptance) the use of cookies.

    You can please check the other thread here:
    https://www.ads-software.com/support/topic/block-omnisend-plugin/#post-15980069

    Thank you.

    Plugin Author Omnisend

    (@omnisend)

    Hey there!
    Thanks for posting in our support thread.

    We can see that you’ve already been in touch with our Support Team therefore we’ll close this thread to keep the communication in a single place.

    If you have any questions or need any assistance, do not hesitate to contact our Support Team, we are available 24/7 and can be reached via In-app chat or email at [email protected].

    Have a great day!

    Thread Starter Daniel P.

    (@danidub)

    Please don’t mark this issue as resolved until is resolved.

    Is true that I have contacted your support team but the issues are still happening and no workaround has being issued.

    So this ticket is not resolved.

    Thank you.

    Unfortunately current implementation does not have any easy way to address this issue, but here is two work arounds:

    1. You can patch the plugin (make change in the plugin). Unfortunately changes will be lost if you will update the plugin.

    To patch the plugin
    1. Open omnisend-connect/omnisend-woocommerce-hooks.php.
    2. Scroll to line 215, you should see the following if statement:
    if (OmnisendHelper::isWooCommercePluginActivated() && OmnisendHelper::checkWpWcCompatibility() ) {
    3. Add additional check accordingly to your needs, e.g. :
    if (OmnisendHelper::isWooCommercePluginActivated() && OmnisendHelper::checkWpWcCompatibility() && isset( $_COOKIE[ 'my_cookie' ] ) ) {

    -OR-

    2. You can add a following function to your functions.php in your theme/child theme:

    function load_omnisend_with_consent( $value, $option ) {
    	if ( ! isset( $_COOKIE[ 'my_cookie' ] ) ) {
    		return null;
    	}
    
    	return $value;
    }
    add_filter( 'option_omnisend_account_id', 'load_omnisend_with_consent', 10, 2 );

    Ideally a ‘wp_footer’ action should be not be set up as anonymous action, so other plugins would have a chance to remove / modify the behaviour.

    NOTE: Your site user will have to reload the page (if its not done automatically after accepting cookies) for Omnisend JS snippet to be loaded.

    • This reply was modified 2 years, 2 months ago by mb00.
    • This reply was modified 2 years, 2 months ago by mb00. Reason: Added a note
    Thread Starter Daniel P.

    (@danidub)

    Hello @mb00, thank you for your idea.

    But this patch as you said will not be compatible with future plugin updates. So I think this is a MUST for the plugin creator to implement ASAP.

    Your approach is valid and a good one, but I prefer something like the Facebook plugin does. They use a class property with a filter function and if that value is true, they inject and enable the plugin and cookies.

    
    /**
    * Determines whether the Pixel should be enabled.
    *
    * @since 2.2.0
    *
    * @return bool
    */
    private function is_pixel_enabled() {
    
      if ( null === $this->is_pixel_enabled ) {
    
        /**
        * Filters whether the Pixel should be enabled.
        *
        * @param bool $enabled default true
        */
        $this->is_pixel_enabled = (bool) apply_filters('facebook_for_woocommerce_integration_pixel_enabled', true );
      }
    
      return $this->is_pixel_enabled;
    }
    

    With this approach we can use something like:

    
    add_filter('facebook_for_woocommerce_integration_pixel_enabled', 'our_function', 20);
    

    If this plugin is public and on GitHub or similar, I don’t mind to take a look and maybe propose a PR.

    The full implementation on the Facebook pixel plugin can be seen here:
    https://github.com/woocommerce/facebook-for-woocommerce/blob/0b4eecc7de4e07bf02d84b746ff4bab0ee0c84aa/facebook-commerce-events-tracker.php

    • This reply was modified 2 years, 2 months ago by Daniel P..

    I’ve proposed 2 options, first option requires patching, the second does not. Adding #2 solution to your functions.php will allow you to update the plugin.

    Thread Starter Daniel P.

    (@danidub)

    Sorry @mb00 I do not pay enough attention on the second method.

    Your solution worked. I post here the snippet for someone needing this to work with https://www.ads-software.com/plugins/gdpr-cookie-compliance/

    
    /* disable omnisend on gdpr_cookie plugin */
    function load_omnisend_with_consent( $value, $option ) {
        if (function_exists('gdpr_cookie_is_accepted')) :
            if (!gdpr_cookie_is_accepted('thirdparty')) :
                return null;
            endif;
        endif;
    
        return $value;
    }
    add_filter( 'option_omnisend_account_id', 'load_omnisend_with_consent', 10, 2 );
    
    /* force reload on gpdr_cookie accept */
    add_action('gdpr_force_reload', '__return_true');
    
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Block cookies until user acceptance’ is closed to new replies.