How To Configure Cookie Policy In Magento 2

Person Using a Macbook and Holding a Credit Card

Magento 2 is a popular e-commerce platform that allows businesses to build their online stores. When running an e-commerce website, it is important to comply with data protection regulations and protect the privacy of your customers. One way to do this is by configuring the cookie policy in Magento 2.

Speed Up Your Magento Store by 300%

What are cookies?

Cookies are small text files that are stored on a user’s computer when they visit a website. Cookies are used to collect data about the user’s behavior on the website, such as their shopping cart items or login information. Cookies allow websites to deliver a more personalized experience to users and to track user activity for marketing or analytical purposes.

However, some cookies can be used to collect personal data without the user’s consent, which is why GDPR (General Data Protection Regulation) and other data protection regulations require websites to obtain the user’s consent before setting cookies that collect personal data.

Configuring the cookie policy in Magento 2

Magento 2 allows you to configure a cookie policy that informs users about the cookies used by your website and obtains their consent before storing personal data. Here are the steps to configure the cookie policy in Magento 2:

Step 1: Enable the cookie restriction mode

In Magento 2, the cookie restriction mode allows you to display a notice to users that informs them about the cookies used by the website and requests their consent before setting cookies that collect personal data. To enable the cookie restriction mode, follow these steps:

  1. Login to the Magento 2 Admin panel
  2. Go to Stores > Configuration
  3. Scroll down to the General section and click on the Web option
  4. Expand the Default Cookie Settings section
  5. Set the Cookie Restriction Mode option to Yes
  6. Set the CMS Page option to the CMS page where you want to display the cookie notice
  7. Save the configuration

Step 2: Create a CMS page for the cookie notice

In Magento 2, you can create a CMS page that displays the cookie notice to users. To create a CMS page for the cookie notice, follow these steps:

  1. Login to the Magento 2 Admin panel
  2. Go to Content > Elements > Pages
  3. Click on the Add New Page button
  4. Enter a Page Title for the cookie notice page
  5. Select the Page Type as Content
  6. Enter the Page Identifier, such as cookie-notice
  7. Enter the Content for the cookie notice, including information about the cookies used by your website and a request for user consent
  8. Save the page

Step 3: Configure the cookie groups

In Magento 2, you can configure cookie groups that define the types of cookies used by your website and whether they collect personal data. To configure the cookie groups, follow these steps:

  1. Login to the Magento 2 Admin panel
  2. Go to Stores > Configuration
  3. Scroll down to the General section and click on the Web option
  4. Expand the Default Cookie Settings section
  5. Click on the Add New button to create a new cookie group
  6. Enter a Group Name for the cookie group
  7. Select the Cookie Type as either Strictly Necessary or Analytics
  8. Enter a Description for the cookie group
  9. Save the cookie group

Step 4: Assign cookies to the cookie groups

After creating the cookie groups, you can assign the cookies used by your website to the appropriate cookie groups. To assign cookies to the cookie groups, follow these steps:

  1. Login to the Magento 2 Admin panel
  2. Go to Stores > Configuration
  3. Scroll down to the General section and click on the Web option
  4. Expand the Default Cookie Settings section
  5. Click on the Add New button to create a new cookie
  6. Enter a Cookie Name for the cookie
  7. Select the Cookie Group that the cookie belongs to
  8. Set the Cookie Lifetime and the Cookie Path according to your website’s requirements
  9. Save the cookie

Step 5: Test the cookie policy

After configuring the cookie policy, you should test it to ensure that it works as intended. Here are some tests you can perform:

  1. Visit your website and verify that the cookie notice appears and requests user consent
  2. Verify that cookies are not set until the user gives their consent
  3. Verify that cookies are set and expire according to their configuration
  4. Verify that the cookie notice is displayed again if the user withdraws their consent

Conclusion

Configuring the cookie policy in Magento 2 is an important step to protect the privacy of your customers and comply with data protection regulations. By enabling the cookie restriction mode, creating a CMS page for the cookie notice, and configuring the cookie groups and cookies, you can provide users with transparency about the cookies used by your website and obtain their consent before collecting personal data. By testing the cookie policy, you can ensure that it works as intended and proactively safeguard your users’ privacy.

Scroll to Top