Skip to content

A Pure JS Firebase Analytics implementation #2644

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
IjzerenHein opened this issue Feb 19, 2020 · 6 comments
Closed

A Pure JS Firebase Analytics implementation #2644

IjzerenHein opened this issue Feb 19, 2020 · 6 comments

Comments

@IjzerenHein
Copy link

Hey guys, first of all, I'm a big fan of Firebase and keep up the great work! 👍 🔥🔥

I'd like to sketch a scenario and would love to hear your feedback. We at expo.io are working on getting Native Firebase working on the Expo Client. Due to the fact that we have a single universal App that can host multiple app experiences (with potentially a different firebase configuration for each project), this is quite a challenge.

One of these challenges is getting Firebase Analytics to work, which is a Singleton and does not seem to support the scenario that we want to provide to our users.
As such, we have created a Pure JavaScript Firebase Analytics implementation that we can load into our environment, on a per project basis. So our users can still log events and test their Firebase Analytics configuration. It uses the (undocumented) Measurement Protocol 2 to do it's logging. It has no external dependencies and doesn't track any app lifecycle events, but you can still call logEvent to log events and set userId & user-properties.

Source code:
https://gist.github.com/IjzerenHein/df3f65093038dd70ad871f926be6f45e

What are your thoughts on this and how do you see the existence of something like this in the Firebase eco-system? Is this something you would support; and to what extend do you consider the Measurement Protocol 2 to be stable?

Ideally, we would like to create multiple instances of the the Native Firebase Analytics module. Perhaps "lite" versions, that don't require hooks into certain lifecycle events, nor a persistent database. Are there plans in this area?

best regards,
Hein

@google-oss-bot
Copy link
Contributor

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.

@hsubox76
Copy link
Contributor

Hi - thanks for the detailed explanation and code.

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.

Smaller questions:

One thing I was a little bit unclear about, when you mention "Native Firebase", do you mean the react-native-firebase project? Which I believe is the one that doesn't work with Expo because of the multiple-apps-in-a-single-app problem. That's a completely separate team, just to clear up any confusion. We don't share any common code. Their repo is here: https://github.com/invertase/react-native-firebase

From what I know about the supporting multiple-apps-in-a-single-app problem, the react-native-firebase team wouldn't actually be able to solve it on their end - their library actually depends on the Firebase iOS and Android SDKs, both of which would have to make significant changes to support react-native-firebase providing this functionality, so this change would be a pretty big effort. I can't say how likely it is or isn't but keep that in mind.

Finally, the Firebase Analytics in this project (the JS SDK, no relation to react-native-firebase) also doesn't work in React Native, but for different reasons - because it is based on gtag.js, the browser JS library for Analytics, and gtag.js requires cookies to work.

@IjzerenHein
Copy link
Author

Hi Christina!

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.

Thank you for the feedback and elaborating on that. We understand there is a danger (for us) and that things might change on the Google side of things. Would there be a way for us to know if any (breaking) changes are coming so we can anticipate? Having access to a changelog/release-notes would be great, but I understand if you want to keep that internal for now.

One thing I was a little bit unclear about, when you mention "Native Firebase", do you mean the react-native-firebase project? Which I believe is the one that doesn't work with Expo because of the multiple-apps-in-a-single-app problem. That's a completely separate team, just to clear up any confusion. We don't share any common code. Their repo is here: https://github.com/invertase/react-native-firebase

From what I know about the supporting multiple-apps-in-a-single-app problem, the react-native-firebase team wouldn't actually be able to solve it on their end - their library actually depends on the Firebase iOS and Android SDKs, both of which would have to make significant changes to support react-native-firebase providing this functionality, so this change would be a pretty big effort. I can't say how likely it is or isn't but keep that in mind.

Yes, we are well aware of react-native-firebase, and that their lib is limited to what the native SDK can offer. The fact that there can be only one native Firebase Analytics instance, is the real limiting factor for us. We figured it would probably be a big effort on Google's part to support multiple native Analytics instances, otherwise you would have already supported it. We understand that most apps probably just use one Firebase App and our case is a bit more specific. This is probably a discussion that should be placed on the iOS/Android Firebase SDK repos, so I will open an issue there.

Finally, the Firebase Analytics in this project (the JS SDK, no relation to react-native-firebase) also doesn't work in React Native, but for different reasons - because it is based on gtag.js, the browser JS library for Analytics, and gtag.js requires cookies to work.

Yes exactly, that was also one of the reasons for creating this community implementation. We'd also rather not build & support something like this, but we also want to provide a working & testable Analytics experience to our Firebase users on the standard Expo client.

Thank you for feedback so far and good to know Google doesn't disapprove of this 👍

regards,
Hein

@dwyfrequency
Copy link
Contributor

@IjzerenHein I haven't seen many updates on this feature request. Is this still an issue for your team? Please let us know

@google-oss-bot
Copy link
Contributor

Hey @IjzerenHein. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@IjzerenHein if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Aug 10, 2023
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

6 participants