How to Enable Cookie Restriction Mode in Magento 2
Cookies are small text files stored in a web user’s browser directory or data folder that has user’s data like username, password, and browsing history.
Cookies help store owners track the customers’ behaviour and hence enhance their on-site experience.
However, prior to using the customers’ data, it is mandatory to have their consent for the same.
As per the EU’s GDPR, the websites need to have the consent of the users regarding the use of cookies and even allow them to deny using the cookies if they wish.
Even if your business does not fall under the European Union, asking users for permission to use cookies and notifying them about the privacy policy is not only an ethical practice but also helps win their trust and increase brand loyalty.
Hence, the default Magento 2.4.x versions have introduced the feature to enable cookie restriction mode in Magento 2 store from the backend.
Cookie Notice helps to implement cookie compliance in Magento 2 store. The notification bar displays a cookie restriction message and contains a button “Allow Cookies” as shown below.
When a user accepts the cookie policy, it proceeds further in the store.
Follow the below method to Enable Cookie Restriction Mode in Magento 2.
Method to Enable Cookie Restriction Mode in Magento 2
- Login to Magento 2 admin panel.
- Navigate to “Stores > Settings > Configuration”.
- Expand the “Default Cookie Settings” section.
- Enter the “Cookie Lifetime” in seconds.
- Enter the “Cookie Path” if you want to make cookies available to other folders. Enter a forward slash to make the cookies available anywhere on the site.
- Enter the subdomain name in the “Cookie Domain” field to make the cookies available to a subdomain.
- Set YES to “Use HTTP Only” to prevent scripting languages from gaining access to cookies.
- Set YES to “Cookie Restriction Mode”.
- Save the configuration by clicking the “Save Config” button.
That’s it
However, if you are using older versions of Magento 2 and want to implement cookie notice in your store, you can opt for Meetanshi’s FREE Magento 2 Cookie Notice extension that shows a neat and simple cookie notification bar or popup in the store frontend which can be even customized as per your theme!
Or, if you don’t want to limit to only cookie compliance law but make your Magento 2 store compatible with the GDPR law, have a look at Magento 2 GDPR extension!
If you have any doubts regarding this post, just mention them in the Comments section below.
I would be happy to help.
Feel free to share the solution with Magento Community via social media.
Thank You.
(Image Source: Magento 2.4 Devdocs)
Comply with the European Union’s guidelines in your Magento 2 by showing cookie notice to the customers.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
4 Comments
Is it possible to add cookie setting button in notice?
For that you will have to customize it or Use our Extension GDPR.
Is cookie disallow action from Customer, do any affect on website?
Hello Nirav,
No, it does not affect the website.
Thank You