With the help of the Magento Cookie Consent extension by Plumrocket, you can effectively block unknown cookies using different options:
- Block Unknown Cookies option in the admin panel
- Google Tag Manager functionality
- Cookie Category script
- The prCookieRestriction JS model
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
-
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:
- Open your website backend and go to the Plumrocket tab
- Choose Configuration under Cookie Consent extension
- Expand the Main Settings section
- Set the Block Unknown Cookies option to Yes
- Click Save Config in the upper right corner to apply the changes
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:
-
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 script
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.-
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:
‘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!
|