Firebase-js-sdk: analytics.isSupported should return false in a Chrome Extension environment

Created on 31 Jul 2020  路  9Comments  路  Source: firebase/firebase-js-sdk


[REQUIRED] Describe your environment

  • Operating System version: __MacOS 10.15.5___
  • Browser version: __Chrome 84.0.4147.89 (Official Build) (64-bit)__
  • Firebase SDK version: [email protected]__
  • Firebase Product: ___analytics__ (auth, database, storage, etc)

[REQUIRED] Describe the problem

Steps to reproduce:

Initialize in a Chrome Extension popup window. analytics.isSupported should return false but returns true.

According to https://firebase.google.com/support/guides/environments_js-sdk, Firebase Analytics is not supported for Chrome Extensions.

Relevant Code:

firebase.initializeApp(firebaseConfig);
const fa = firebase.analytics();
firebase.analytics.isSupported().then(function (result) {
    console.log("result", result);
});
analytics

All 9 comments

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

Side note: I really wish Firebase Analytics supports Chrome Extensions. I initially implemented it for my extension, but had to rip it out for analytics.js. Not sure why Firebase Analytics doesn't when analytics.js works fine.

Firebase Analytics works on top of gtag.js which requires cookie to work, so Firebase analytics doesn't work in non browser environments.

I suppose you were using the measurement protocol v1? gtag.js uses measurement protocol v2. I don't know what the differences are between v1 and v2, but I think you will need to use v2 in order to support all the features we support currently, in case you decide to implement it yourself. v2 is undocumented and is not stable right now though, see discussion on this topic in https://github.com/firebase/firebase-js-sdk/issues/2644.

1) We will change the check to make sure it looks specifically for a browser extension environment.

2) The reason analytics.js works and Firebase Analytics doesn't is that as Feiyang mentioned, Firebase Analytics wraps gtag.js, which is needed because it supports App+Web analytics properties while analytics.js does not (it supports Web properties). Firebase Analytics uses App+Web properties.

The reason Google Analytics in general has trouble with Chrome extensions is because they have a chrome-extension:// protocol instead of http:// which analytics code normally rejects. analytics.js has an option called checkProtocolTask that you can set to false to bypass this problem. gtag.js doesn't have this option.

There's a question here that covers this dilemma. If gtag.js ever offers a similar option we can integrate it into Firebase Analytics.

I see, thanks @Feiyang1 @hsubox76. checkProtocolTask is exactly what I turn off to make analytics.js work after much digging. It works ok, better than nothing.

It's frustrating to have to fight the web vs. app battle over the past decade. Web apps are apps too. Routes are just root views. JavaScript and browser are just implementation details. How we think about user behavior doesn't change.

I know this is more of an issue with Google Analytics. I appreciate what you guys do on Firebase.

The fix has been released 7.18.0

  1. We will change the check to make sure it looks specifically for a browser extension environment.
  2. The reason analytics.js works and Firebase Analytics doesn't is that as Feiyang mentioned, Firebase Analytics wraps gtag.js, which is needed because it supports App+Web analytics properties while analytics.js does not (it supports Web properties). Firebase Analytics uses App+Web properties.

The reason Google Analytics in general has trouble with Chrome extensions is because they have a chrome-extension:// protocol instead of http:// which analytics code normally rejects. analytics.js has an option called checkProtocolTask that you can set to false to bypass this problem. gtag.js doesn't have this option.

There's a question here that covers this dilemma. If gtag.js ever offers a similar option we can integrate it into Firebase Analytics.

Would it be possible to wrap analytics.js too, at least partially? Is there any reasonable workaround to provide data to Firebase Analytics?

As mentioned above, analytics.js doesn't support App+Web analytics properties (ID begins with "G-"), which is the type of analytics property associated with all Firebase apps. It works with Web properties (ID begins with "UA-"). If you have an existing analytics Web property, I think it wouldn't be associated with any Firebase project and I'm not sure if there's a good reason to use the Firebase JS SDK to log to it instead of using analytics.js directly.

You can look at https://github.com/firebase/firebase-js-sdk/issues/2644 mentioned above for a workaround some people have come up with based on a currently unstable API. If finding a workaround is very important, despite the unstable API and manual steps, you can look into trying something like what they have done.

As mentioned above, analytics.js doesn't support App+Web analytics properties (ID begins with "G-"), which is the type of analytics property associated with all Firebase apps. It works with Web properties (ID begins with "UA-"). If you have an existing analytics Web property, I think it wouldn't be associated with any Firebase project and I'm not sure if there's a good reason to use the Firebase JS SDK to log to it instead of using analytics.js directly.

You can look at #2644 mentioned above for a workaround some people have come up with based on a currently unstable API. If finding a workaround is very important, despite the unstable API and manual steps, you can look into trying something like what they have done.

Thanks for the reply. I will check the above link. The goal is to be able to access Analytics data in Firebase too, so that I can access the data in services such Remote Config.

Was this page helpful?
0 / 5 - 0 ratings