firebasefirebase-analyticsgtag.jsadsense-apigdprconsentform

How to configure firebase for consent and data compliance on web?


I'm currently working on a consent management system for my platform where we use firebase for analytics and AdSense for Ads. However the api is badly documented on this subject and there doesn't seem to be simple, straightforward ways to configure consent options like when using gtag consent commands directly, which don't seem to be supported on the firebase api.

After some days of research I've come up with initialising analytics with these gtag configs/properties: allow_google_signals: false, allow_ad_personalization_signals: false, to disable ad data collection and personalization. After that I set analytics collection to false, which is straightforward enough. However this isn't ideal as I'm initialising analytics and it might not get used. Is there a better way to do this?

The effect I'm aiming for is the same as calling gtag('consent', 'default', { 'ad_storage': 'denied', 'analytics_storage': 'denied' }); which doesn't seem to be possible to do as firebase uses gtag internally and exposes no access to it besides to it's config command.


Solution

  • For everyone searching for a solution and stumbling over this question (just like I did). It's possible, just like Nik said, but with the JS (Web 9) syntax:

    import {setConsent} from "firebase/analytics";
    
    setConsent({
      analytics_storage: "denied",
      ad_storage: "denied"
    });
    

    Then you can use your own logic/routines to set them back to "granted", if the user consents to it.

    But you're right, it's very hard to find the correct documentation to this. I found it here: https://firebase.google.com/docs/reference/js/analytics#setconsent