Add TCF v2.2 bridge mode for external CMP integration (v1.3.0)

New cmp_mode setting toggles between the built-in banner (default,
unchanged) and a bridge mode that defers banner UX to an external
IAB TCF v2.2 certified CMP — e.g. Google's free Privacy & messaging
(Funding Choices) or Tarteaucitron.js — and listens to __tcfapi to
keep custom-script gating, attribution preservation, the att_cc_consent
cookie cache and the WP Consent API bridge in sync. Lets sites that
need a Google-certified CMP for EEA/UK AdSense/AdMob serving keep
using this plugin for everything except the consent UI itself.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-30 14:10:58 +01:00
parent 7059c45e20
commit eb35fdabb6
7 changed files with 238 additions and 7 deletions

View File

@@ -12,6 +12,13 @@ A WordPress plugin implementing Google Consent Mode v2 with session attribution
2. **Tracking script (priority 2)** - Loads gtag.js or GTM. In Advanced mode, loads immediately. In Basic mode, deferred until consent.
3. **Footer** - Banner HTML + enqueued `banner.js` and `banner.css`.
### CMP Mode
The `cmp_mode` setting toggles between two operating modes:
- **`self` (default)** - this plugin renders the banner, owns the consent decision, and writes the `att_cc_consent` cookie. Original behaviour.
- **`tcf_bridge`** - an external IAB TCF v2.2 certified CMP (e.g. Google's free Privacy & messaging / Funding Choices banner, Tarteaucitron.js) renders the banner and emits the official TC string + `gtag('consent', ...)` calls. The plugin suppresses its own banner/modal/`consent default`, and instead loads `public/js/tcf-bridge.js`, which listens to `__tcfapi('addEventListener', 2, …)`, maps TCF purposes back to the three categories, and feeds `AttConsent.update()` so custom-script gating, attribution preservation and the WP Consent API bridge continue to work. Used when the site needs to satisfy Google's CMP requirement for EEA/UK/CH AdSense/AdMob traffic.
### Key Files
- `includes/class-frontend.php` - Orchestrates the output order. The `output_consent_defaults()` method generates the critical inline script.