stormid / components

UI components
https://stormid.github.io/components/
MIT License
2 stars 2 forks source link

Add Google consent mode support #266

Closed mjbp closed 1 month ago

mjbp commented 1 month ago

Closes #264

Adds support to optionally pass consent information to Google for their basic 'consent mode' https://developers.google.com/tag-platform/security/concepts/privacy#consent_mode_overview

It works by setting mappings between banner-configured cookie categories and categories defined by Google, then pushing consent events to the dataLayer for Google libraries to pick up and use to manage Google cookies.

On each page load a default event of 'denied' for all Google categories is pushed, before update events are pushed once consent is ascertained from an existing banner cookie, or interactions with the banner or form.

For some reason Tag Manager seems to be unable to read spread props or arrays of data, instead insisting on a function that pushes arguments t the dataLayer - see docs here - https://developers.google.com/tag-platform/security/guides/consent?consentmode=basic#tag-manager. We have tried and failed to implement without using function arguments, so arguments it is! Unfortunately Jest chokes on arguments, so we have tests describing the cases but commented out so they do not run, and the functionality has been manually verified.