Menu

How to Block Unknown Cookies

With the help of the Magento Cookie Consent extension by Plumrocket, you can effectively block unknown cookies using different options:

Why Do I Need to Block Unknown Cookies

The proper compliance with the Cookie Consent policy requires all cookies to be blocked before a customer gives consent. The Magento 2 Cookie Consent Extension allows merchants to specify all cookies used and prevent all unknown cookies from being set directly from the Magento admin panel.

How to Block Unknown Cookies With Cookie Consent Extension

  1. Use the Block Unknown Cookies option

    In order to block unknown cookies, you should set the Block Unknown Cookies option to Yes in the configuration of the Magento Cookie Consent extension:

    1. Open your website backend and go to the Plumrocket tab
    2. Choose Configuration under Cookie Consent extension
    3. Expand the Main Settings section
    4. Set the Block Unknown Cookies option to Yes
    5. Click the Save Config button in the upper right corner to apply the changes
     
    magento 2 cookie consent extension block unknown third-party cookies option
     

    However, since Javascript has limited control over the cookie setting, the Block Unknown Cookies option control setting cookies by JS libraries (jQuery.cookie and jQuery.mage.cookie) that are integrated into the Cookie Consent extension.

    Also, most third-party cookies are passed by Javascript due to the use of JS code (e.g., document.cookie = "name=value";). Since it is impossible to automatically check and stop the running code, the extension cannot prevent cookies from being set by document.cookie, and the blocking is performed by deleting these set cookies.

    All things considered, we recommend the most effective way to control setting cookies by integrating analytics, custom extension functionality, etc. with the Cookie Consent extension. The extension provides you with built-in tools for this purpose:

    1. Google Tag Manager

    You can use the functionality of the Cookie Consent extension to assign Google Tag Manager Script to a specific Cookie Category. This allows enabling/disabling Google Tag Manager when a visitor enables/disables the corresponding cookie category. In case you already use the Google Tag Manager, make sure it is executed only by Cookie Consent Google Tag Manager functionality. Go to the extension’s backend -> Configuration -> Google Tag Manager Settings to configure it.
    Cookie Category allows adding JS code that will be executed depending on whether a customer allowed or declined this cookie category. In order to add the JS code, use the Head Scripts and  Footer Miscellaneous HTML fields in the Edit Cookie Category page.
    1. The prCookieRestriction JS model

    The prCookieRestriction JS model can be used to find out whether a particular category is allowed by a customer or not. Hence, cookies set by Javascript might be completely blocked by wrapping the code as in the example below: 

    magento 2 cookie consent extension block unknown cookies js model

    ‘marketing’ is the key identifier of the Marketing category set in the Manage Cookie Categories grid in the Cookie Consent extension. The script will be executed if a customer allows the marketing category.

    To find out more about the prCookieRestriction JS model, go to the following file:

    Plumrocket/CookieConsent/view/frontend/web/js/model/restriction.js

    If you have any difficulties blocking the unknown cookies, you are always welcome to contact our support team. They will be more than happy to help you!



Still Need Help?