Custom Cookies
GDPR module will automatically show all registered cookies on a cookie-settings page. All you need is to register your cookie. Sometimes you may want to use your own cookie group. To make it possible you must register your cookie group too.
Register Cookie
-
Add
cookies_load_before
event listener inetc/events.xml
file:<event name="swissup_gdpr_cookies_load_before"> <observer name="vendor_module_register_cookies" instance="Vendor\Module\Observer\RegisterCookies" /> </event>
-
Create
RegisterCookies
observer that will register a cookie:<?php namespace Vendor\Module\Observer; class RegisterCookies implements \Magento\Framework\Event\ObserverInterface { /** * Prepare forms * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { $observer->getCollection()->addItemFromArray([ 'name' => 'cookie_name', 'description' => "Cookie description.", 'group' => 'marketing', // necessary, analytics, advertisement, marketing ]); } }
-
Check the “cookie-settings” page. Now it will have your cookie too.
Register Cookie Group
-
Add
cookie_groups_load_before
event listener inetc/events.xml
file:<event name="swissup_gdpr_cookie_groups_load_before"> <observer name="swissup_gdpr_register_cookie_groups" instance="Vendor\Module\Observer\RegisterCookieGroups" /> </event>
-
Create
RegisterCookieGroups
observer that will register a cookie group:<?php namespace Vendor\Module\Observer; class RegisterCookieGroups implements \Magento\Framework\Event\ObserverInterface { /** * Prepare forms * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { $observer->getCollection()->addItemFromArray([ 'code' => 'cookie_group_code', 'title' => 'Cookie Group', 'description' => "Cookie Group Description.", 'sort_order' => 100, 'required' => false, ]) } }
-
Now, you can use “cookie_group_code” to link your cookies with your group.