Open Andrea-Dispe opened 11 months ago
I started using the library recently and ran into the same roadblock
I'm assuming these settings would go in the "gtagOptions" when initializing at least
ReactGA.initialize([
{
trackingId: "your GA measurement id",
gtagOptions: {...}, // <-----
}
]);
Sadly fiddling with its "any" type doesn't sound very appealing to me
So I've resorted to manually removing the cookies on consent denied by the user kinda like this article from dev.to says As well as initializing without an ID when consent is denied, then initializing correctly when consent is granted
Would be awesome if this could be done directly with the library or is on the roadmap!
@ReyasHey that example doesn't really accomplish the goal though, it's a very strict on or off. My understanding of the google consent policy is we can still use analytics even if the user denies access, it's just that google will not store cookies, and will strip out all the user identifying information. We really need a way to enable/disable this in react-ga4 without having to completely turn off analytics.
I think we can use this before initialization:
ReactGA.gtag("consent", "default", {
ad_storage: "denied",
ad_user_data: "denied",
ad_personalization: "denied",
analytics_storage: "denied",
});
and later
ReactGA.gtag("consent", "update", {
analytics_storage: "granted",
});
@PaloSP that worked, thanks for the info!
Not a real issue but I am trying to figure out how to set and update google CMP (Consent Management Platform) with react-ga4. According to the official google doc official google doc on consent mode this script:
will be added to the head and then the consent mode banner will have to update it with this:
How to achieve this just by using react-ga4?