Magento makes use of RequireJS - the auto-blocking feature schedules the loading of scripts in a similar manner to RequireJS, resulting in conflicts between the two, and auto-blocking is therefore not currently compatible with RequireJS.
Using Cookiebot in manual mode requires marking up scripts for prior consent. This process is described here: https://www.cookiebot.com/en/manual-implementation-guide/
Adding Cookiebot in Magento 2.3.4 is different than it was previously in Magento 1, as described in this guide.
The following 3 steps will help you get Cookiebot up and running in Magento 2.3.4:
- Create a new JavaScript (js) file:
app/design/frontend/VENDOR/THEME/Magento_Theme/web/js/cookiebot.js
Replace VENDOR/THEME with your own theme name and add the following content:
require([ 'https://consent.cookiebot.com/uc.js?cbid=00000000-0000-0000-0000-000000000000', 'domReady!' ], function () { 'use strict'; });
You'll need to replace00000000-0000-0000-0000-000000000000
with your own Domain Group ID. You can find this on the Your scripts tab in the Manager. - Create a new XML file:
app/design/frontend/VENDOR/THEME/Magento_Theme/layout/default_head_blocks.xml
Once again, replace VENDOR/THEME with your own theme name and add the following content:<?xml version="1.0"?> <page
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"
> <head> <script src="Magento_Theme::js/cookiebot.js"/> </head> </page>
- Flush all caches
The Cookiebot script should now load and construct a client-side JavaScript object named Cookiebot
/ CookieConsent
which exposes public properties, methods, events and callback functions.
You can find an overview of these in our Developer Documentation: https://www.cookiebot.com/en/developer/.
Comments
2 comments
Create a new JS file:
Replace VENDOR/THEME with your own theme name and add the following content:
That's it. No need to create a JS file and include it in the XML file.
If you want to have a convenient way how to install Cookiebot in your Magento store, you can also use our free extension:
Cookiebot Extension for Magento 1
Cookiebot Extension for Magento 2
Please sign in to leave a comment.