Search by

hryvinskyi / magento2-cookie-consent-meta

hryvinskyi

Meta pixel consent for hryvinskyi/magento2-cookie-consent, with Meta's known cookies and blocking rules

Package info

github.com/hryvinskyi/magento2-cookie-consent-meta

Type:magento2-module

pkg:composer/hryvinskyi/magento2-cookie-consent-meta

Statistics

Installs: 2

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2026-12-01 13:06 UTC

This package is auto-updated.

Last update: 2026-12-01 13:08:40 UTC


README

Meta pixel consent for hryvinskyi/magento2-cookie-consent, with Meta's known cookies and blocking rules.

What it does for a store

The store's own Meta pixel snippet stays where it is; this module puts it under consent in one of two ways.

  • Gated (the default). Blocking rules hold the pixel back until the visitor allows its category: the library's address (connect.facebook.net/en_US/fbevents.js), a fragment of the snippet that sets up the pixel's queue function, and every inline script that calls fbq(, so a store's separate event script waits with the snippet. Once the pixel runs it is told the consent with its consent command: grant when the category is allowed, revoke when it is not.
  • Load and adapt. The pixel loads with the page: the consent runtime defines the pixel's queue function, queues consent revoke and loads the library from the configured address, ahead of the store's snippet, then tells the pixel the default and the stored consent before the snippet's init. No rule holds anything back. When something already defined fbq earlier in the head, the part defines and loads nothing and only tells the consent.

It also adds Meta's first-party cookies, _fbp and _fbc, to the consent catalogue of known trackers, and a row to the consent setup wizard's Blocking step: a switch between holding the pixel back and loading it with the choice told to it, and a select for its category. The module's own switch only makes the row read-only.

Requirements

  • hryvinskyi/magento2-cookie-consent and hryvinskyi/magento2-admin-setup-wizard, and the platform's Store and Config modules (what composer.json and etc/module.xml declare). PHP 8.1 or higher.

Installation

composer require hryvinskyi/magento2-cookie-consent-meta
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush

Configuration

Stores › Configuration › Hryvinskyi Extensions › Cookie Consent › Meta Pixel (hryvinskyi_cookie_consent/meta/*), every field per default, website and store view.

Setting Path Default
Enabled meta/enabled on
Implementation meta/mode gated (adapt: load and adapt)
Category of the pixel meta/category marketing
Pixel library address (load and adapt only) meta/library https://connect.facebook.net/en_US/fbevents.js; an address that is not https is read as this one

A value that reaches the configuration without the form and breaks a rule is read as its default; a category the store does not have is never allowed, so the pixel is told revoke.

What it adds to the consent module

All in the global etc/di.xml: the runtime part signal-meta (Model\Runtime\MetaSignalPart), the known-tracker source meta, the blocking rule source meta (Model\Rule\MetaRules, which contributes rules only in the gated mode and describes on the Blocking rules page what it does on each store view), the wizard settings meta_enabled, meta_mode, meta_category and the Blocking-step row meta (address connect.facebook.net). The two modes are the items of Model\Mode\ModePool.

Limits

  • The fbq( rule is a plain substring: an inline script that holds another identifier ending in the same letters followed by ( is held back too, and waits for the category like the pixel.
  • The rule on the library is narrowed to that one file, because the host also serves scripts of other Meta features that a rule on the whole host would hold back.
  • In the gated mode the module creates no global: the pixel's snippet returns at once when window.fbq exists, so a function put there ahead of it would keep the pixel from ever loading.
  • When the library's script cannot be inserted, load and adapt keeps the queue function: the store's snippet then returns early and the pixel stays off rather than running before it is told the consent.

Translations

The admin wording ships in en_US and 25 more locales: the official languages of the European Union, Norwegian Bokmål and Ukrainian. The translations are machine-made; have them read by a native speaker before a store relies on them.

Tests

  • Unit: vendor/bin/phpunit -c app/code/Hryvinskyi/CookieConsentMeta/phpunit.xml.dist; the browser part: npm test and npm run check in Test/Js.
  • Integration: the platform's harness in dev/tests/integration.
  • Browser flows: Test/E2e/, run with the @hryvinskyi/magento2-e2e package from the shop's e2e/ directory.