Replies: 1 comment
-
Thank you for your message, it's been very helpful! I can confirm that updating consent status after initialization seems impossible, neither
This seems to work for me, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm running into an issue that, I believe, should be very common, but couldn't find an answer to (only an unanswered Stack Overflow question).
I would like to use consent mode and only allow analytics to use cookies once the user has given consent through clicking on a button in a cookie consent banner. The procedure is described in this video from Google Analytics.
Quick summary of the procedure:
'denied'
and show a banner on the website that asks the user for consent. (UsesetConsent()
from Firebase SDK for this)getAnalytics()
orinitializeAnalytics()
from Firebase SDK)The problem is that I can't find a way to update the consent settings after the
initializeAnalytics()
function has been called. According to the Google Analytics documentation, the analytics script should be initialized though, even if the user has not given any consent yet. Calling thesetConsent()
function again once the user has given consent seems to have no impact – no cookies are set in the browser after calling the function. I assume that thegtag()
function needs to be called with the'update'
parameter, but this isn't possible through the Firebase SDK – there is noupdateConsent()
function. Also, I could not figure out how to access or call thegtag()
function manually afterinitializeAnalytics()
has initialized the script.The only way I have found to make Google Analytics properly work after the user has given consent is to reload the page. Then, the default consent will be based on the allowed consent stored in local storage and the
initializeAnalytics()
call will set the Google Analytics cookies. I would like to prevent this page reload though as it seems unnecessary.Does anyone know how to update consent settings only after a user has given consent? This seems like such a common use-case to me that I assume it should be doable without a page refresh?
Edit:
It seems that
setConsent()
does call thegtag
script with theupdate
parameter:firebase-js-sdk/packages/analytics/src/api.ts
Line 771 in 00235ba
My question remains, though. How can I make sure that the analytics cookies are set in the browser and analytics events are sent when I update the consent from
denied
togranted
?Beta Was this translation helpful? Give feedback.
All reactions