Skip to content

analytics.isSupported should return false in a Chrome Extension environment #3522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rayshan opened this issue Jul 31, 2020 · 9 comments
Closed

Comments

@rayshan
Copy link

rayshan commented Jul 31, 2020

[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);
});
@google-oss-bot
Copy link
Contributor

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

@rayshan
Copy link
Author

rayshan commented Jul 31, 2020

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.

@Feiyang1
Copy link
Member

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 #2644.

@hsubox76
Copy link
Contributor

  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.

@rayshan
Copy link
Author

rayshan commented Aug 1, 2020

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.

@Feiyang1
Copy link
Member

The fix has been released 7.18.0

@motiejunas
Copy link

  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?

@hsubox76
Copy link
Contributor

hsubox76 commented Aug 25, 2020

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.

@motiejunas
Copy link

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.

@firebase firebase locked and limited conversation to collaborators Sep 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants