[astro-gtm] Add GDPR Consent Mode v2 with configurable default#1291
[astro-gtm] Add GDPR Consent Mode v2 with configurable default#1291
Conversation
🦋 Changeset detectedLatest commit: 55a2d6d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdds GDPR Consent Mode v2 support to the astro-gtm package: new Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/astro-gtm/README.md`:
- Around line 154-169: The consent example uses window.dataLayer directly in the
allConsentGranted function, but the component supports a custom dataLayerName
prop; update the example and documentation to reference the configurable name
(e.g., use the value of dataLayerName or fallback to window.dataLayer) when
pushing consent updates, and show an explicit note or example demonstrating how
to call allConsentGranted with a custom dataLayerName (referencing the
allConsentGranted function and the dataLayerName prop/customDataLayer
identifier) so pushes go to the correct global array.
🧹 Nitpick comments (2)
packages/astro-gtm/src/GoogleTagManager.astro (2)
92-96: Consider guarding against an emptydefaultConsentobject.If a consumer passes
defaultConsent={{}}(empty object), it's truthy and will push an empty consent default to the dataLayer, which is a no-op but unnecessary. A stricter guard would also check that the object has at least one key.Proposed fix
- if (defaultConsent) { + if (defaultConsent && Object.keys(defaultConsent).length > 0) { w[dataLayerName].push(['consent', 'default', defaultConsent]); }
2-10: Addwait_for_updateparameter toConsentDefaultstype for Google Consent Mode v2.Google Consent Mode v2 supports the
wait_for_updateproperty (in milliseconds) to tell GTM how long to wait for a consent update before firing tags, commonly used with async consent management platforms (e.g.,wait_for_update: 500). Add it to the type for completeness.Proposed addition to ConsentDefaults
export type ConsentDefaults = { ad_storage?: 'granted' | 'denied'; analytics_storage?: 'granted' | 'denied'; ad_user_data?: 'granted' | 'denied'; ad_personalization?: 'granted' | 'denied'; functionality_storage?: 'granted' | 'denied'; personalization_storage?: 'granted' | 'denied'; security_storage?: 'granted' | 'denied'; + wait_for_update?: number; };
Summary by CodeRabbit
New Features
Documentation
Chores