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
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:
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.
Google Tag Manager
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.
Cookie Category script
The prCookieRestriction 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:
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!