hryvinskyi / magento2-cookie-consent-microsoft
Microsoft UET and Clarity consent for hryvinskyi/magento2-cookie-consent, with Microsoft's known cookies and blocking rules
Package info
github.com/hryvinskyi/magento2-cookie-consent-microsoft
Type:magento2-module
pkg:composer/hryvinskyi/magento2-cookie-consent-microsoft
Requires
- php: ^8.1
- hryvinskyi/magento2-admin-setup-wizard: ^1.0
- hryvinskyi/magento2-cookie-consent: ^1.0
- magento/framework: *
- magento/module-config: *
- magento/module-store: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Microsoft UET and Clarity consent for hryvinskyi/magento2-cookie-consent, with Microsoft's known cookies and blocking rules.
What it does for a store
- Tells both tags the choice. A part of the consent runtime tells the advertising tag (UET)
ad_storagethrough commands pushed ontowindow.uetq, and the session-analytics tag (Clarity)ad_Storageandanalytics_Storagethroughwindow.clarity('consentv2', …). The default goes before either tag runs, then the stored consent, then every change. When a visitor withdraws every key after one was granted, Clarity's cookies are erased withwindow.clarity('consent', false). - Two implementations per tag. Advanced (the default): the tag loads with the page and adapts to the consent it is told. Basic: the tag is also held back until its category is allowed, by the blocking rules of its own source —
microsoft_uet(the tag's script onbat.bing.comand the inline loader that requestsbat.bing.com/bat.js) ormicrosoft_clarity(the loader onwww.clarity.ms/tag/, the library onscripts.clarity.msand the loader's inline form). Each tag has an implementation and a category of its own; a tag with none set follows the shared ones. - Declares Microsoft's first-party names in the consent catalogue of known trackers:
_uetsid,_uetvid,_uetmsclkid(cookies, and local storage keys with their_expcompanions) and Clarity's_clck,_clsk,_cltk. - Two rows in the consent setup wizard's Blocking step, Microsoft Advertising and Microsoft Clarity: a switch between the basic and the advanced implementation and a select for the tag's category. A row shows the shared implementation and category while the tag's own hold none, and is read-only while the module or the tag is switched off.
Requirements
hryvinskyi/magento2-cookie-consentandhryvinskyi/magento2-admin-setup-wizard, and the platform's Store and Config modules (whatcomposer.jsonandetc/module.xmldeclare). PHP 8.1 or higher.
Installation
composer require hryvinskyi/magento2-cookie-consent-microsoft bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush
Configuration
Stores › Configuration › Hryvinskyi Extensions › Cookie Consent › Microsoft Consent (hryvinskyi_cookie_consent/microsoft/*), every field per default, website and store view.
| Setting | Path | Default |
|---|---|---|
| Enabled | microsoft/enabled |
on |
| Advertising tag (UET) used | microsoft/uet_enabled |
on |
| Session-analytics tag (Clarity) used | microsoft/clarity_enabled |
on |
| Advertising tag: implementation, category | microsoft/uet_mode, microsoft/uet_category |
empty: the shared ones |
| Session-analytics tag: implementation, category | microsoft/clarity_mode, microsoft/clarity_category |
empty: the shared ones |
| Implementation (both tags, unless set per tag) | microsoft/mode |
advanced (basic) |
| Category that lets the tags load (unless set per tag) | microsoft/basic_category |
marketing |
The category ad_storage follows |
microsoft/ad_storage_category |
marketing |
The category analytics_storage follows |
microsoft/analytics_storage_category |
statistics |
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 its key stays denied.
What it adds to the consent module
All in the global etc/di.xml: the runtime part signal-microsoft (Model\Runtime\MicrosoftSignalPart), the known-tracker source microsoft, the blocking rule sources microsoft_uet and microsoft_clarity (virtual types of Model\Rule\MicrosoftRules, each describing on the Blocking rules page what it does on a store view), and the wizard settings and Blocking-step rows microsoft_uet (address bat.bing.com) and microsoft_clarity (addresses www.clarity.ms and scripts.clarity.ms).
Limits
- The two queue objects are the only globals the module creates, only for a tag that is on and only when none exists, the way each vendor's snippet does. It loads neither tag itself.
- In the advanced implementation the tags load before a choice and are told denied; what they send while denied is Microsoft's to decide. Use the basic implementation to keep them off the page.
- The rules hold back the scripts that load the tags. The vendors' sign-in and dashboard pages and the endpoints the tags send data to are not scripts and have no rule.
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/CookieConsentMicrosoft/phpunit.xml.dist; the browser part:npm testandnpm run checkinTest/Js. - Integration: the platform's harness in
dev/tests/integration. - Browser flows:
Test/E2e/, run with the@hryvinskyi/magento2-e2epackage from the shop'se2e/directory.