See the way the Cookie Consent (GDPR) for Magento 2 extension works.
Increase customer retention by giving them the opportunity to regulate their cookie usage. Implement a GDPR compliant cookie policy to your store with Cookie Consent extension for Magento 2.
The extension uses Geo IP Database to detect site visitors' location. Please, go to Stores → Configuration → Amasty Extensions → Geo IP Data.
You can get the databases automatically or import your own data.
Hit the Download and Import button to make the extension download the updated CSV dump file and import it into your database automatically.
To import the files from your own source, use the Import option. Path to the files should look like this (the part 'var/amasty' should be replaced with your folders’ names):
var/amasty/geoip/GeoLite2-City-Blocks-IPv4.csv var/amasty/geoip/GeoLite2-City-Blocks-IPv6.csv var/amasty/geoip/GeoLite2-City-Locations-en.csv
You can enable IP forcing, which makes it possible to set a specific IP address that will be used instead of the visitor's real IP address when determining geolocation. The feature is useful while configuring or testing the extension.
Enable Force IP - set to Yes to replace the real IP address.
Force IP Address - specify the address to use instead of a real one.
To adjust cookie policy settings, go to Stores → Configuration → Amasty Extensions → Cookie Consent.
Expand this tab to configure the basic setting of the extension.
Enable Cookie Policy Bar - set to Yes to enable Cookie Notice Bar on Magento 2 frontend.
Hide the Cookie Bar if No Decision Was Taken - if Yes, the cookie bar will not be displayed to a customer on new pages if he doesn't accept or decline cookies. Thus, the customer will be less distracted from purchasing.
Countries Restrictment - enable this option to adjust the visibility of the Cookie Policy Bar on the frontend according to customer location.
Other customers won't see the popup and a Cookie CMS Page. Consent logs are disabled for them as well.
Cookie Log Auto-Cleaning Period (Days) - set the period after which the records that were stored will be automatically cleaned.
Cookie Bar Style - choose the cookie bar type suitable for your store:
If customers accept all cookies regardless of a bar type, the cookie bar automatically disappears.
If they want to find extra information or allow specific cookies by clicking Custom Cookies (button name is customizable), they will see the following popup:
Thus, they can click the toggles and accept the particular cookies only.
From this popup, they can also find extra details about each cookie type by clicking More Information in the popup and see the info:
The extension also adds a special link to the store footer so that customers could find information about cookies and revoke previously given consents at any time. The data is also displayed in the pop-up.
Each bar type has multiple customization options.
For Classic bar you can specify the following settings:
Cookie Bar Location - place a bar either at the top or in the footer.
Notification Text - provide the text to display in a popup. You can use any HTML-tags in this field. Please, mind the security.
With a handy color picker toolset the colors for the:
Also, you can customize the buttons.
For each button you can customize:
Save configuration and Flush Magento Cache to see the changes. An example of design customization:
For the side bar type there are the following settings:
Here you can customize:
For buttons, the settings are the same as for the Classic bar type.
The sample of customization:
For a pop-up style, manage the following settings:
Adjust the:
Check the result of customization:
To arrange cookies into essential and optional categories, go to Customers → Cookie Groups.
With the extension, you can manage all your cookie categories in a handy grid.
On the grid the ID, Cookie Group Name and Description are displayed. Also, you can see if each group Is Essential and Is Enabled.
To configure any group, click Edit in the Action column.
To delete several groups in one click, tick them and choose the Delete option in the Actions dropdown menu.
To create a new category, click Add New Group.
Enabled - choose Yes to activate the group.
Is Essential - set to Yes to make the group obligatory. In this case, the customers will have to allow this cookie group to get access to the website.
Cookie Group Name - specify the title of the cookie group that will be displayed to the customers on the frontend and on the grid in the admin panel.
Description - fill in the information about the usage of the group so that the customers could decide whether to allow this group or not.
Assigned Cookies - select the cookies to include in the group. See how to assign cookies to a particular category in this section.
Save the configuration.
To manage cookies, go to Customers → Cookies.
With the extension, you can track and filter cookies on a separate grid by its ID, Cookie Group and Cookie Name
To view or change the configuration of a cookie, click Edit in the Action column.
To delete cookies, tick them and choose the Delete option in the Actions dropdown menu.
To create a new cookie, hit the Add New Cookie button. All the information you provide about a cookie will be displayed to customers on the frontend in the appropriate section.
Cookie Name - specify the title of the cookie.
Cookie Provider - specify the company that uses and analyzes a particular cookie.
Description - fill in some information about the usage of the cookie.
Cookie Lifetime - set the lifetime of a cookie that will be displayed to customers on the Cookie CMS page.
Cookie Type - choose the type of the request in which a cookie is sent: 1st Party or 3rd Party.
Cookie Group - assign the cookie to a particular group.
To find the list of all consents and customers data, go to Customers → Cookie Consents Log.
You can find all needed info in one place. The grid allows to track consents by customer Name, Email, IP Address, Website, Consent Type, Date and Consent Status. This data can be useful for different consents analysis.
Now the extension includes JavaScript and PHP APIs to let you block cookies added on your frontend by JS component.
To implement the compatibility, do the following:
For example, you have the JS component or simple script that adds some cookie on your frontend:
define([ 'jquery', 'uiCollection', // Some other dependencies ], function ($) { 'use strict'; return Collection.extend({ initialize: function () { this._super(); this.yourCustomMethodToAddCookie(); return this; }, /** * Method to initialize custom cookie */ yourCustomMethodToAddCookie: function () { $.mage.cookies.set('my-awesome-cookie', 'cookie-data-value'); } }); });
With our module, you can make this cookie GDPR-compliant. Use one of the approaches below (or even both if you wish).
Pros: Your custom JS code will be executed on demand without any delays
Cons: It's impossible to check essential cookies. Thus, you should avoid using this approach when you have different essential cookies on your stores.
Let's modify the component to make it GDRP-compilant via Synchronous approach:
define([ 'jquery', 'uiCollection' ], function ($) { 'use strict'; return Collection.extend({ initialize: function () { this._super(); this.yourCustomMethodToAddCookie(); return this; }, /** * Method to initialize custom cookie */ yourCustomMethodToAddCookie: function () { var disallowedCookies = document.cookie.match(new RegExp('(^| )amcookie_disallowed=([^;]+)')) || []; var allowedCookies = document.cookie.match(new RegExp('(^| )amcookie_allowed=([^;]+)')) || []; var isAllowedToRunScript = !!allowedCookies.length && (!disallowedCookies[2] || disallowedCookies[2].split('%2C').indexOf('my-awesome-cookie') === -1) if (isAllowedToRunScript) { $.mage.cookies.set('my-awesome-cookie', 'cookie-data-value'); } } }); });
Pros: All GDRP Cookie JS logic and your custom JS logic is fully compliant. You will have full control over cookies added via custom JS code and run a custom code after cookie acceptance
Cons: Your JS code will be executed after some GDRP Cookie JS logic with delay.
Let's modify the component to make it compliant via Asynchronous approach:
define([ 'jquery', 'uiCollection' ], function ($, Collection) { 'use strict'; return Collection.extend({ initialize: function () { this._super(); this.cookieCompilantMethodWrapper(this.yourCustomMethodToAddCookie.bind(this)); // Wrap your method with error resistant wrapper this.initCookieEventListeners(); // Add event listener to run custom code immediately after the client accepts the cookies. return this; }, /** * Cookie Allow and Save actions event listener */ initCookieEventListeners: function () { $('body').on('amcookie_save amcookie_allow', function () { this.cookieCompilantMethodWrapper(this.yourCustomMethodToAddCookie.bind(this)); }.bind(this)); }, /** * Cookie compilant wrapper for your method */ cookieCompilantMethodWrapper: function (cookieSetterCallback) { require(['Amasty_GdprCookie/js/model/cookie'], function (cookieModel) { if (cookieModel.isCookieAllowed('my-awesome-cookie')) { cookieSetterCallback(); } }, function(errorMessage) { ` cookieSetterCallback(); // In case if not existing of Amasty component we MUST run the callback }); }, /** * Method to initialize custom cookie */ yourCustomMethodToAddCookie: function () { $.mage.cookies.set('my-awesome-cookie', 'cookie-data-value'); } }); });
Find out how to install the Cookie Consent for Magento 2 via Composer.