Cookie compliance integration for Magento

Nelson
Written by NelsonLast updated 9 hours ago

There are two ways to install CookieScript on Magento 2 / Adobe Commerce:

  1. By using the CookieScript module (recommended)

  2. By adding the code in the design configuration

We recommend using the module: it adds the banner to every store view, supports Google Consent Mode v2, and allows the CookieScript domains in Magento's Content Security Policy.

Note: Use only one method to install CookieScript. If you switch from one method to another, remove the previous code first.

Method 1: Installing the CookieScript module

The module requires Magento Open Source or Adobe Commerce 2.4.4 or newer and PHP 8.1 or newer. You can install it with Composer or from a zip file.

The module is available on Packagist as cookiescript/module-banner. In the root folder of your Magento installation, run:

composer require cookiescript/module-banner

Option B: Install from a zip file

  1. Download the latest version (zip) from the CookieScript Magento module on GitHub.

  2. In your Magento installation, create the folder app/code/CookieScript/Banner/.

  3. Unzip the files into that folder, so that registration.php ends up at app/code/CookieScript/Banner/registration.php.

Enable the module

After Option A or B, run these commands in the root folder of your Magento installation:

bin/magento module:enable CookieScript_Banner
bin/magento setup:upgrade
bin/magento setup:di:compile                  # production mode only
bin/magento setup:static-content:deploy -f    # production mode only
bin/magento cache:flush

Set up the banner

  1. In your CookieScript account, open your banner and go to Install.

  2. Configure geo-targeting (if needed).

  3. Select Shopify and click Copy code. This tab shows only your banner's source link (it starts with https://cdn.cookie-script.com/s/), which is what the Magento module needs:

    image.png
  4. In your Magento Admin, go to Stores > Configuration > CookieScript > Cookie Banner.

  5. In the Banner section, paste the link into CookieScript source link. Other values are rejected when you save.

  6. Keep Script location in the page set to Header and Script position set to First (the defaults). The higher the script is in the page, the better CookieScript can block third-party cookies until the visitor agrees.

  7. Set Enable CookieScript banner to Yes and click Save Config.

  8. Optional: to use Google Consent Mode v2, open the Google Consent Mode v2 section, set Enable Google Consent Mode to Yes, choose the default state for each consent type and Wait for update (ms), and click Save Config. Under Regional settings, you can add different defaults for specific regions, for example US-CA or DE, FR.

All done! Saving the settings empties Magento's Full Page Cache, so the banner shows on the next visit to your store.

Several stores: every setting can be changed per website or store view. Use the Scope switcher at the top of the configuration page.

Update: if you installed with Composer, run composer update cookiescript/module-banner, then the commands from Enable the module again (except the first one).

Uninstall: to remove the module and its saved settings, run bin/magento module:uninstall --remove-data CookieScript_Banner.

Method 2: Adding the code in the design configuration

  1. In your CookieScript account, open your banner and go to Install.

  2. Configure geo-targeting (if needed).

  3. Select Script tag and click Copy code:

    image.png
  4. In your Magento Admin, go to Content > Design > Configuration.

  5. Find the store view where you want to show the banner and click Edit.

  6. Expand the HTML Head section and paste the copied code at the top of the Scripts and Style Sheets field.

  7. Click Save Configuration and flush the Magento cache (System > Cache Management).

Note: Magento's Content Security Policy can block scripts from domains that are not allowed, especially on checkout pages. If the banner doesn't load there, use Method 1: the module allows the CookieScript domains automatically.

Note: If the banner doesn't appear after installation, check whether a caching extension or browser extension is preventing it from showing.

Did this article help you solve your issue?