feat: add the ability to use cookies for consent #466
Closed
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.
Hey there,
I added a feature that allows us to remember consent between pages and sessions. If a prop the
GoogleAnalytics
component has theconsentCookie
prop, it'll grab the JSON data from that cookie and apply it. I also added a couple utility functions to get and set those cookies from the browser. Additionally this PR adds a hook that simplifies the process of creating consent prompts. I've left an example usages in the README.Currently, I only allow the developer to use either
consentCookie
ordefaultConsent
but not both. Another way we could handle this is to use the value ofdefaultConsent
to dictate the default when the cookie isn't present. The current method is more GDPR friendly, however it might be nice to offer more options. Making consent granted by default right now would involve waiting for a component to mount and running either theconsent
function or theupdateConsent
function from theuseConsent
hook. I was wondering if I could get some opinions on this?Resolves #447
TODO