meetanshi / magento2-cookie-notice

meetanshi/magento2-cookie-notice

cookienotice

magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Warning Tests: N/A Security: Pass OSL-3.0, AFL-3.0

Are you the maintainer of meetanshi?

Packagento pulls meetanshi's Composer packages from the public registry so buyers can find them here.

Claim the namespace to take ownership, publish new releases directly, and start charging for premium versions.

Claim this namespace →

Meetanshi Cookie Notice for Magento 2

A simple, customizable cookie notice bar, card or modal for your Magento 2 store. It is free.

This extension shows a notice and remembers the visitor's answer. It does not block cookies or scripts by itself. For full cookie consent management (cookie categories, script blocking, Google Consent Mode, consent logs), see Meetanshi Google Consent Mode V2.

  • Version: 1.0.9
  • Magento Open Source and Adobe Commerce 2.4.7 to 2.4.9
  • PHP 8.2, 8.3, 8.4 and 8.5
  • Themes: Luma and Hyvä (tested with Hyvä Default 1.5.4). No separate Hyvä compatibility module is needed.

Features

  • Layouts: a bar at the top or bottom, a floating card in any corner, or a centered modal.
  • Design: Light, Dark, Minimal and Brand presets, colors, corners, shadow, animation, button style (filled, outline or text link), border and width, with a live preview in the admin.
  • Mobile first: on small screens the notice becomes a bottom sheet with large buttons.
  • Buttons: Accept, Decline and a privacy policy link, or fewer. With "Accept only" the button says "Got it".
  • Cookie Settings button: lets visitors change their answer later. Any element with the class mcn-open opens the notice too.
  • Hide on pages: checkout, the privacy policy page, or your own list of paths (with * wildcards).
  • Message HTML: <strong>, <em>, <br> and links. Put {privacy_policy_link} where the policy link should go.
  • Translations: default texts in English, French, German, Spanish, Italian, Dutch and Portuguese.
  • Accessible: screen reader roles, keyboard support, a visible focus outline, and no animation for visitors who turn off motion on their device.
  • Fast and safe: one small script, no jQuery, no inline scripts or styles (works with a strict Content Security Policy), and no requests to other websites.

Installation

php bin/magento module:enable Meetanshi_CookieNotice
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

Settings: Stores > Configuration > Meetanshi > Cookie Notice.

The visitor's answer

The answer is stored in the first-party cookie mcn_consent with the value accepted or rejected (SameSite=Lax, plus Secure on HTTPS). When the cookie is missing, the visitor has not answered yet.

Visitors who answered under version 1.0.8 or older (cookie cookienotice) are converted automatically.

For developers

Events

The notice dispatches these events on document:

Event When event.detail
mcn:ready The notice has started { value }
mcn:accepted The visitor accepted (button, auto accept or scroll) { value: 'accepted', expires }
mcn:rejected The visitor declined (button or Esc in the modal) { value: 'rejected', expires }
mcn:closed The notice was closed for any reason { value }
mcn:reopened The visitor opened the notice again { value }

value is 'accepted', 'rejected' or null. expires is a Date, or null for a session cookie.

Example: load your own script only after the visitor accepts.

function loadMyScript() {
    var script = document.createElement('script');

    script.src = 'https://example.com/tracking.js';
    document.head.appendChild(script);
}

if (window.MeetanshiCookieNotice && window.MeetanshiCookieNotice.getConsent() === 'accepted') {
    loadMyScript();
} else {
    document.addEventListener('mcn:accepted', loadMyScript, { once: true });
}

JavaScript API

Call What it does
MeetanshiCookieNotice.getConsent() Returns 'accepted', 'rejected' or null
MeetanshiCookieNotice.open() Opens the notice
MeetanshiCookieNotice.reset() Forgets the answer and opens the notice

The API exists after the notice script has started (after mcn:ready).

Open the notice from your own link

<a href="#" class="mcn-open">Cookie Settings</a>

This works unless "Cookie Settings Button" is set to "None".

Hyvä

Hyvä has no RequireJS. On Hyvä pages (layout handle hyva_default) the template prints the settings in
<script type="application/json" id="mcn-config"> and loads notice.js with a normal <script src defer> tag.
The script then starts by itself. Events, the JavaScript API and mcn-open links work the same as on Luma.

After switching a store between Luma and Hyvä, flush the cache so that no page of the other theme is served.

Styling

All colors and sizes are CSS variables on .mcn-root (for example --mcn-bg, --mcn-accept-bg, --mcn-radius). The class names start with mcn (.mcn, .mcn__btn, .mcn-badge). The stylesheet is view/base/web/css/notice.css.

Support

meetanshi.com · [email protected]

Changelog

1.0.9

Compatible with Magento Open Source and Adobe Commerce 2.4.7 to 2.4.9, PHP 8.2 to 8.5.

New

  • Three layouts: bar (top or bottom), floating card (any corner or center) and centered modal.
  • Style presets (Dark, Light, Minimal, Brand), corner roundness, shadow, animation, button style (filled, outline, text link), card width and border.
  • Live preview in the admin, with a phone, tablet and desktop switch and a color contrast check.
  • Color picker with a hex field (no third-party script), and inline error messages under every field.
  • "Buttons to Show": Accept + Decline + privacy link, Accept + Decline, or Accept only ("Got it").
  • "Cookie Settings" button (floating, your own links, or none) so visitors can change their answer. Any link with the class mcn-open opens the notice.
  • Hide the notice on the privacy policy page, on checkout pages, or on your own list of paths (with * wildcards).
  • Message supports bold, italic, line breaks and links, and the {privacy_policy_link} placeholder.
  • Default texts in French, German, Spanish, Italian, Dutch and Portuguese.
  • Developer events (mcn:ready, mcn:accepted, mcn:rejected, mcn:closed, mcn:reopened) and a small JavaScript API (MeetanshiCookieNotice.getConsent(), .open(), .reset()).
  • Hyvä theme support, built in (no separate compatibility module): the notice starts without RequireJS on Hyvä pages, and keeps working on the Luma based checkout.
  • Mobile bottom sheet, keyboard support, screen reader roles, visible focus outline, and no animation for visitors who turn motion off.

Changed

  • "Accept Cookies Automatically" now saves the answer even when "Autohide" closed the notice first (before, the answer was lost and the notice came back on the next page). It never overrides a Decline.
  • When Enable Cookie Notice is set to No, the Content, Buttons and Design groups are hidden too (before, only their fields were hidden).
  • Saving the settings clears the Full Page Cache, so a changed or disabled notice reaches pages that were already cached.
  • The notice is now one stylesheet and one small script (no jQuery, no inline scripts or styles), so it works with a strict Content Security Policy.
  • The visitor's answer is stored in the cookie mcn_consent (SameSite=Lax, Secure on HTTPS). The old cookienotice cookie is converted automatically.
  • "When User Closes the Notice" now works as described: never show again (365 days), hide for the rest of the day, or hide for the session.
  • The Decline button now stores the answer "rejected" instead of acting like Accept.
  • The README and admin texts no longer claim "GDPR compliant". The extension shows a notice and remembers the answer.
  • Google Fonts are no longer loaded. The notice uses your theme font, or a system font stack.
  • All existing configuration paths are kept, so saved settings survive the update.

Fixed

  • Settings saved from the admin are now validated (numbers, colors, text length, allowed values, paths).
  • Colors, sizes and fonts are checked again when the page is built, so a bad value in the database cannot break the page or inject CSS.
  • Privacy policy link is built with Magento's CMS page helper and gets rel="noopener noreferrer" when it opens in a new window.
  • CSP whitelist file used a wrong schema address.
  • Stray .DS_Store files removed from the package.

Security

  • All output is escaped for its context. The message HTML is cleaned with an allow-list (a, strong, em, br; links only to http, https, mailto and relative URLs).
  • No request to another website when the page loads.
  • Removed the bundled third-party color picker script.
  • The settings page needs the permission Meetanshi_CookieNotice::cookienotice.

Removed

  • Third-party jscolor.js, the Google Fonts request, inline scripts, and the unused widget code.

1.0.8

  • Previous release.
Versions
Version Stability QA Status Compatibility Released
1.0.9 stable Pass Magento 2.4.7-2.4.9 Details 2026-11-30 09:31:37
1.0.8 stable Fail Not yet tested Details 2026-05-22 12:00:21
1.0.7 stable Not tested Not yet tested Details 2026-01-08 10:05:17

Requires 1

Package Constraint
php ~5.5.0|~5.6.0|~7.0.0|7.0.2|7.0.4|~7.0.6|~7.1.0|~7.2.0|~7.3.0|~7.4.0|^8.0.0|^8.1.0|^8.2.0|^8.3.0|^8.4.0|^8.5.0

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

Code Quality

Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.

Static analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

Static analysis results
Tool Status Findings Summary
PHPCS Pass 0
PHPMD Pass 0
Cpd Pass 0
Composer validate Info 1 valid; 1 advisory note (composer validate --strict)

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 1 1
2.4.8 1 1
2.4.9 1 1

Tests

Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Integration tests

Integration tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Security

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0
License
OSL-3.0, AFL-3.0
Authors

More from meetanshi

View vendor
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.