feat(audience): automatic CMP consent detection (GCM v2 + IAB TCF)#2842
Merged
feat(audience): automatic CMP consent detection (GCM v2 + IAB TCF)#2842
Conversation
…v2 + IAB TCF) Add consentMode: 'auto' init option to the pixel that auto-detects consent from existing Consent Management Platforms on the page, removing the need for studios to write custom JS to wire up consent. Supported CMPs: - Google Consent Mode v2 (via window.dataLayer) — covers OneTrust, Cookiebot, TrustArc, Didomi, Osano and most major CMPs - IAB TCF v2 (via window.__tcfapi) — vendor-agnostic standard for EU markets Detection polls up to 3 times over ~2.4s for async CMP loading, then registers listeners for real-time consent changes mid-session. CMP detection lives in @imtbl/audience-core so the web SDK can reuse it. Refs: SDK-87 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolve conflict in pixel.ts: include both CmpDetector and IdentityType type imports. Update consentMode test assertion for new createConsentManager signature (added httpSend param). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
View your CI Pipeline Execution ↗ for commit 1e79fce
☁️ Nx Cloud last updated this comment at |
✅ Pixel Bundle Size — @imtbl/pixel
Budget: 10.00 KB gzipped (warn at 8.00 KB) |
Add eslint-disable for no-underscore-dangle on __tcfapi (external API name). Fix object-curly-newline formatting in test file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nattb8
reviewed
Apr 9, 2026
nattb8
reviewed
Apr 9, 2026
nattb8
reviewed
Apr 9, 2026
nattb8
reviewed
Apr 9, 2026
- Add onTimeout callback to startCmpDetection for distinguishing "CMP said none" from "no CMP found" - Use else-if to prevent duplicate page view when CMP detects synchronously - Replace sessionId guard with initialPageViewFired flag for reliable deferred page view tracking - Narrow consentMode type to literal 'auto' (remove ConsentLevel union) - Add setConsent() deferred page view as fallback for failed CMP detection - Update tests for all fixes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace weak setConsent test with two precise tests that verify: - setConsent auto-fires the deferred initial page view on consent upgrade - Repeated setConsent calls don't fire duplicate page views Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nattb8
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
consentMode: 'auto'init option to the pixel for automatic consent detection from existing CMPs on the pagewindow.dataLayer, interceptsdataLayer.pushfor real-time updates)window.__tcfapi, registersaddEventListenerfor consent changes)@imtbl/audience-coreso the web SDK can reuse itConsent mapping
analytics_storage: 'denied'/ no Purpose 1noneanalytics_storage: 'granted'+ad_storage: 'denied'/ Purpose 1 onlyanonymousanalytics_storage: 'granted'+ad_storage: 'granted'/ Purpose 1 + 3/4/5fullDe-scoped
Direct CMP integrations (OneTrust, Cookiebot) moved out of scope — GCM + TCF cover the vast majority of deployments since both OneTrust and Cookiebot fire Google Consent Mode updates. Context preserved on SDK-87 for a future issue.
Test plan
consentMode: 'auto'(deferred page view, CMP upgrade/downgrade, teardown)Refs: SDK-87
🤖 Generated with Claude Code