hryvinskyi / magento2-cookie-consent-data-layer
Bridges hryvinskyi/magento2-cookie-consent and the GA4 data layer: the consent admin shows the Google tags the data layer loads as managed by it
Package info
github.com/hryvinskyi/magento2-cookie-consent-data-layer
Type:magento2-module
pkg:composer/hryvinskyi/magento2-cookie-consent-data-layer
Requires
- php: ~8.3.0||~8.4.0
- hryvinskyi/magento2-cookie-consent: ^1.0
- hryvinskyi/magento2-data-layer: ^1.0
- hryvinskyi/magento2-data-layer-frontend-ui: ^1.1
- magento/framework: *
- magento/module-store: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Connects hryvinskyi/magento2-cookie-consent with the GA4 data layer (hryvinskyi/magento2-data-layer and hryvinskyi/magento2-data-layer-frontend-ui).
What it does
On a store view where the data layer is on and loads a Google Tag Manager container or gtag.js, the consent admin (the setup wizard's Blocking step and the Blocking rules page) shows the blocking rule rows covering the hosts those scripts load from as managed by GA4 Data Layer: read-only, with no switch and no category select. The hosts are the container's script host and, when gtag.js loads, Google's default host. Whether gtag.js loads is the data layer's own rule, asked through its destinations, never repeated here. Hosts are compared without case and without a trailing dot.
Managed changes only what the admin draws and offers. Which scripts are held back, and how consent reaches Google's tags, stay as the consent module and whichever module sends Google's consent commands configure them.
Requirements
hryvinskyi/magento2-cookie-consent,hryvinskyi/magento2-data-layer,hryvinskyi/magento2-data-layer-frontend-uiand the platform's Store module (whatcomposer.jsonandetc/module.xmldeclare); PHP 8.3 or 8.4, as the data layer.- The consent runtime runs before the data layer's loaders in
<head>, so the consent default is set before any Google tag starts. Both modules place their scripts this way by default. - The data layer pushes into
dataLayer. When Google's consent commands come from another module, that module's data layer name must bedataLayeras well; this module cannot check it.
Installation
composer require hryvinskyi/magento2-cookie-consent-data-layer bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush
It has no settings of its own.
What it adds
The tag-management source data_layer (Model\DataLayerTagManagement, an implementation of the consent module's TagManagementSourceInterface) in the consent module's Model\Rule\TagManagementSources, in the global etc/di.xml.
Limits
- The data layer's server-side events are not under consent: this module covers only the tags the data layer loads in the browser.
- It cannot warn when the data layer loads Google's tags and no consent signal reaches them.
Translations
The 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/CookieConsentDataLayer/phpunit.xml.dist. - Integration: the platform's harness in
dev/tests/integration. - Browser flows:
Test/E2e/, run with the@hryvinskyi/magento2-e2epackage from the shop'se2e/directory.