Firebase-js-sdk: Firebase Analytics (Web) does not work in Non-browser Envs

Created on 8 Oct 2019  Â·  14Comments  Â·  Source: firebase/firebase-js-sdk

  • Operating System version: macOS Mojave
  • Browser version: Electron 5.0.10
  • Firebase SDK version: 7.1.0
  • Firebase Product: Analytics

Describe the problem

Steps to reproduce:

On Electron, Analytics seems to load correctly but no events, sessions or users are logged.

Relevant Code:

Include Firebase using the script tag (as importing the module from NPM fails due to gRPC).

<!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.1.0/firebase-app.js"></script>

<!-- If you enabled Analytics in your project, add the Firebase SDK for Analytics -->
<script src="https://www.gstatic.com/firebasejs/7.1.0/firebase-analytics.js"></script>

<!-- Add Firebase products that you want to use -->
<script src="https://www.gstatic.com/firebasejs/7.1.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.1.0/firebase-firestore.js"></script>
<script>
    firebase.initializeApp({
        ...
    });
    firebase.analytics()
</script>

While Firebase seems to load, and a new googletagmanager gets installed on the page, not analytics events seem to reach Firebase dashboard.

analytics

Most helpful comment

I see. Then I will have to continue relying on the "classic" Google Analytics with Measurement Protocol. Hopefully, Google Analytics web+apps will support that as a data source at some point. It's a pity because a user-based analytics makes more sense for an Electron app (like for mobile apps) than the current session-based analytics.

All 14 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

It's a limitation on gtag.js which Firebase Analytics depends on and uses cookies to manage sessions and users. Electron has document.cookies, but It seems that it is implemented/accessed differently, and gtag.js can't access it.

So unfortunately it means Firebase Analytics is not going to work in Electron.

I see. Then I will have to continue relying on the "classic" Google Analytics with Measurement Protocol. Hopefully, Google Analytics web+apps will support that as a data source at some point. It's a pity because a user-based analytics makes more sense for an Electron app (like for mobile apps) than the current session-based analytics.

@Feiyang1 Do you have any links or leads on more information regarding this? As of now, we can't use Firebase Analytics in either the the main process (as Firebase node sdk doesn't support Analytics) or in the renderer, due to this. Great shame.

Nope


From: Nikolaj Selvik notifications@github.com
Sent: Saturday, February 8, 2020 10:55:45 AM
To: firebase/firebase-js-sdk firebase-js-sdk@noreply.github.com
Cc: Sharma, Rahul RahulDutt.Sharma@monotype.com; Manual manual@noreply.github.com
Subject: Re: [firebase/firebase-js-sdk] Firebase Analytics (Web) does not work on Electron (#2243)

@Feiyang1https://protect-us.mimecast.com/s/XQXaCQW2m6iQrPvfPqo0G Do you have any links or leads on more information regarding this? As of now, we can't use Firebase Analytics in either the the main process (as Firebase node sdk doesn't support Analytics) or in the renderer, due to this. Great shame.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://protect-us.mimecast.com/s/ElKHCR60nPh6BW4cP6tg4, or unsubscribehttps://protect-us.mimecast.com/s/iyKVCVOkr7TJ9yqtJjvEM.

Hi, to clear up any confusion, Firebase Analytics is a wrapper around the gtag.js library. Any expansion of its capabilities depend on gtag.js adding those capabilities. I don't know of any plans right now to support use of gtag.js in non-browser environments, but as it is a separate team, I don't want to speak for them.

Basically, any ability to do this is contingent on changes that would need to be made in a separate library that we do not maintain.

Thanks for this information.

I will try contacting them


From: Christina Holland notifications@github.com
Sent: Wednesday, February 12, 2020 3:27:04 AM
To: firebase/firebase-js-sdk firebase-js-sdk@noreply.github.com
Cc: Sharma, Rahul RahulDutt.Sharma@monotype.com; Manual manual@noreply.github.com
Subject: Re: [firebase/firebase-js-sdk] Firebase Analytics (Web) does not work on Electron (#2243)

Hi, to clear up any confusion, Firebase Analytics is a wrapper around the gtag.js libraryhttps://protect-us.mimecast.com/s/fxVgCYEnxytY6rJu0xNYZ. Any expansion of its capabilities depend on gtag.js adding those capabilities. I don't know of any plans right now to support use of gtag.js in non-browser environments, but as it is a separate team, I don't want to speak for them.

Basically, any ability to do this is contingent on changes that would need to be made in a separate library that we do not maintain.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://protect-us.mimecast.com/s/bUR7C1wnqGSgEVDcpRce2, or unsubscribehttps://protect-us.mimecast.com/s/5IaUC2kor7trEMJs2D13U.

What about Measurement Protocol?
If Firebase Analytics is based on the same underlying data of the classic Google Analytics, what prevents simply sending raw hit data?

I would like to chime in, I used heap by making the file protocol a standard scheme, this allowed heap to treat electron file:/// based ui as a webpage. Without this heap would not create cookies and hence wont work

Firebase analytics had a simialr issue where it would not start even. By doing the above it makes the cookies and does some requests to load and start but never fully start

If the problem is a simple check for browser agent then, this should be enhancable


From: Marco Ancona notifications@github.com
Sent: Wednesday, February 12, 2020 5:40:18 AM
To: firebase/firebase-js-sdk firebase-js-sdk@noreply.github.com
Cc: Sharma, Rahul RahulDutt.Sharma@monotype.com; Manual manual@noreply.github.com
Subject: Re: [firebase/firebase-js-sdk] Firebase Analytics (Web) does not work on Electron (#2243)

What about Measurement Protocol?
If Firebase Analytics is based on the same underlying data of the classic Google Analytics, what prevents simply sending raw hit data?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://protect-us.mimecast.com/s/WlKwCn5oXgswmZxfJKtpc, or unsubscribehttps://protect-us.mimecast.com/s/yBOFCo20Kjh9vV8SV31dC.

@marcoancona My understanding is that Firebase/App+Web GA properties uses v2 of the GPM, which is undocumented and thus potentially subject to changes or it simply never being made available for use as an open protocol. I think there is a definite lack of clarity surrounding the technical details of the Google/Firebase analytics offerings as of right now that should be adressed.

References:

https://www.thyngster.com/technical-overview-of-new-appweb-properties/
https://www.simoahava.com/analytics/getting-started-with-google-analytics-app-web/

Hi, to clear up any confusion, Firebase Analytics is a wrapper around the gtag.js library. Any expansion of its capabilities depend on gtag.js adding those capabilities. I don't know of any plans right now to support use of gtag.js in non-browser environments, but as it is a separate team, I don't want to speak for them.

Basically, any ability to do this is contingent on changes that would need to be made in a separate library that we do not maintain.

Are the Firebase Analytics for C++, iOS, Android and Unity also just wrappers of the gtag.js library? I would have reckoned they used the v2 GPM protocol referenced in my above comment directly.

has this been resolved by “Using Firebase in Electron: Tips and Tricks” by Christina Holland https://link.medium.com/7JbbcIhXm4 ?

No, as mentioned in the third paragraph of that article, Firebase is not officially supported for use in Electron. That is a guide with some tips for making as much of it work as possible.

For questions about potential use of Measurement Protocol, see this comment in another issue:

First, the key part of your question, about the use of Measurement Protocol v2: It is not currently stable and that team is still in the process of working out all the use cases they plan to support. Because of this, we can't officially incorporate its use into the Firebase JS SDK at this time. If you or anyone wants to create a community solution based on it, the fact that it is still in progress and not yet officially supported should be taken into consideration.

The user who opened that issue also links to some code they wrote to supply their desired functionality using the unsupported Measurement Protocol API, if you also want to try that route, given the tradeoff of it being unsupported and liable to change.

Finally, to clear up any confusion, the mobile SDKs do not use gtag.js or Measurement Protocol, but platform-specific APIs for interacting with Analytics.

Based on this answer, it seems you can make Google Analytic work on non-browser environment: https://stackoverflow.com/questions/3591847/google-analytics-from-a-file-url/47251006#47251006

Would it be possible to configure Firebase Analytic the same way?

Even better, would it be possible to have Firebase Analytic doing it itself?

  • for userId, it would simply hash the user uuid from Firebase Auth _(and automatically switch value when a user connect or disconnect. And use localStorage if Firebase Auth is not used or no user is connected)_
  • for storage analytics when offline, it would use local storage
  • for checkProtocolTask, it would default to "null"
  • for pageView, it would probably still be the responsibility of the dev to notify Firebase Analytic of a page navigation, because I can't see a "standard" way to do it...

This would be awesome!

And if it is not possible to use Firebase Analytic SDK in Cordova, is there any issue with using the GTag Library? Considering that my "Firebase Analytic" is linked with my "Google Analytic", what are the functional differences between using FA and GA? Would it impact Firebase Remote Config for example (particularly its ability to use Analytic criteria for the conditions)?

Thanks!

Was this page helpful?
0 / 5 - 0 ratings