You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to get analytics to work with consent banner and sending advanced consent information with the setConsent method.
Steps and code to reproduce issue
In the projet, initialize Firebase first. I consider app to be a constant containing the firebase application instance in the following snippet:
import{setAnalyticsCollectionEnabled,setConsent}from'firebase/analytics'constanalytics=app.analytics()// Add some delay to wait for gtag loadingsetTimeout(()=>{console.log('Called')setAnalyticsCollectionEnabled(this._analytics,consent)setConsent({ad_personalization: 'denied',ad_storage: 'denied',ad_user_data: 'denied',analytics_storage: 'granted',functionality_storage: 'granted',personalization_storage: 'denied',security_storage: 'granted',})},5000)
Using Tag Assitant, I can see the tag events. However, I get this result:
The granted value is missing and there is strange numbered items.
Doing a some step-by-step debugging, I found the call to gtag. The third parameter which should be the ConsentSettings (see Set up consent mode on websites is set to the second parameter update instead of the third.
@megamisan, thanks for reaching out to us. I was able to replicate the behavior you've mentioned. Also, thanks for sending a PR for a possible fix. I'll raise this to our engineering team or bring someone here that can provide more context about it. I’ll update this thread if I have any information to share.
Operating System
Windows 11 23H2
Browser Version
Edge 124.0.2478.51
Firebase SDK Version
10.11.0
Firebase SDK Product:
Analytics, AppCheck, Auth, Firestore, Functions, Storage
Describe your project's tooling
Vue.js app.
Describe the problem
I'm trying to get analytics to work with consent banner and sending advanced consent information with the
setConsent
method.Steps and code to reproduce issue
In the projet, initialize Firebase first. I consider
app
to be a constant containing the firebase application instance in the following snippet:Using Tag Assitant, I can see the tag events. However, I get this result:
The granted value is missing and there is strange numbered items.
Doing a some step-by-step debugging, I found the call to gtag. The third parameter which should be the
ConsentSettings
(see Set up consent mode on websites is set to the second parameterupdate
instead of the third.The
setConsent
method code is here packages/analytics/src/api.ts#L768.It trigger the call to the gtagWrapper function with this line:
The
wrappedGtagFunction
is an instance of thegtagWrapper
function found in packages/analytics/src/helpers.ts#L279.When the method is called before initialization of
gtag
, the call is made correctly.setContent
sends the settings to_setConsentDefaultForInit
and the packages/analytics/src/initialize-analytics.t:_initializeAnalytics
s#L129 function use these settings correctly.I see two possible fixes:
'update'
parameter insetConsent
, thus the diff:I recommend the first option.
Original commits:
Some checks failed for this commit but where not fixed. This test packages/analytics/src/api.test.ts#L143 should have detected the issue.
The text was updated successfully, but these errors were encountered: