Refactor CookieBanner for configurable cookie preferences and analytics initialization
As a developer,
I want the `CookieBanner` to display and control cookie preferences based on a version-controlled configuration object,
with the ability to re-trigger the banner when the configuration version changes.
Additionally, I want the analytics initialization to be conditional and support different analytics functions
based on the `CookieBanner` configuration and user choices,
while ensuring Google Analytics initialization still works with the provided tracking ID.
Background
The current implementation of the CookieBanner handles cookie preferences and displays the banner based on hardcoded constants and logic tied directly to the existing setup. Additionally, Google Analytics initialization is tied to specific cookie choices without supporting alternative analytics configurations. To enhance flexibility, maintainability, and user experience, we need to refactor the system to be configuration-driven and capable of initializing analytics dynamically based on user preferences.
Acceptance Criteria
-
The CookieBannerpreferences are defined as a version-controlled configuration object that can be set via code or passed as an initialization parameter. -
The CookieBannerchecks the configuration version; if the version changes, the banner is displayed to the user again to re-confirm choices. -
Analytics initialization supports multiple analytics functions and initializes conditionally based on user-selected cookie preferences. -
The initGoogleAnalyticsfunction can still be called with a tracking ID string and initializes correctly when invoked. -
Documentation is updated to explain the new configuration-driven approach and analytics initialization mechanism.
Implementation Notes
- Refactor
CookieBannerto accept a configuration object defining cookie categories, descriptions, and default behaviors. - Add a version-checking mechanism that re-displays the banner when the configuration version changes.
- Implement a dynamic analytics initialization function that mounts the appropriate analytics based on user choices.
- The configuration object should be type-safe and validated on initialization.