Skip to content
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

Add Firebase Analytics for [KMP] #517

Closed
DenisPopkov opened this issue May 29, 2024 · 13 comments
Closed

Add Firebase Analytics for [KMP] #517

DenisPopkov opened this issue May 29, 2024 · 13 comments
Labels
API coverage Request for missing APIs

Comments

@DenisPopkov
Copy link

No description provided.

@DenisPopkov DenisPopkov added the API coverage Request for missing APIs label May 29, 2024
@atonamy
Copy link

atonamy commented Jun 3, 2024

Yes, we absolutely need it

@DenisPopkov
Copy link
Author

DenisPopkov commented Jun 3, 2024

@atonamy
I wrote my own solution via Firebase REST API. You can check it out in article — https://habr.com/ru/articles/818891/

@atonamy
Copy link

atonamy commented Jun 4, 2024

@atonamy I wrote my own solution via Firebase REST API. You can check it out in article — https://habr.com/ru/articles/818891/

According to this article implementation looks pretty simple and straightforward I'm surprised why is still not part of firebase-kotlin-sdk ?

I wonder if this secret key can be retrieved somehow by using tools of this firebase-kotlin-sdk itself?

@DenisPopkov
Copy link
Author

DenisPopkov commented Jun 4, 2024

@atonamy

I wonder if this secret key can be retrieved somehow by using tools of this firebase-kotlin-sdk itself?

You need to obtain a secret key for each application within your Firebase console project and hardcode it either inside BuildConfig or in GitHub secret keys, for instance. The secret key will not change regardless. By using firebase-kotlin-sdk you can't get secret keys.

@atonamy
Copy link

atonamy commented Jun 4, 2024

@DenisPopkov

@atonamy

I wonder if this secret key can be retrieved somehow by using tools of this firebase-kotlin-sdk itself?

You need to obtain a secret key for each application within your Firebase console project and hardcode it either inside BuildConfig or in GitHub secret keys, for instance. The secret key will not change regardless. By using firebase-kotlin-sdk you can't get secret keys.

Then how firebase-kotlin-sdk internally call other Firebase API without exposing secret key?

@DenisPopkov
Copy link
Author

@atonamy, google-services.json file contains all the necessary information for making requests to the SDK. However, for the REST API, you would need secret keys, which can be found in the official documentation — https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events?hl=ru&client_type=firebase

@atonamy
Copy link

atonamy commented Jun 4, 2024

@atonamy, google-services.json file contains all the necessary information for making requests to the SDK. However, for the REST API, you would need secret keys, which can be found in the official documentation — https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events?hl=ru&client_type=firebase

@DenisPopkov

how to use google-services.json instead with KMP any example for Analytics? Using secret key is not a solution for us.

@DenisPopkov
Copy link
Author

@atonamy
You can still use google-services.json for all Firebase services for iOS and Android. However, for Desktop, you can't do this as Firebase doesn't support it natively. If you're only using Analytics in your project, you don't need google-services.json at all.

Using secret key is not a solution for us

Why? It's created by the developer for each project and stored inside the application or somewhere. This is quite normal.

@DenisPopkov
Copy link
Author

@atonamy
In a Kotlin Multiplatform (KMP) project targeting only iOS and Android, you can use google-services.json without secret keys by leveraging the Firebase Analytics SDK provided by the official libraries. Additionally, you can write expect/actual implementations to integrate the Firebase Analytics SDK into your shared Kotlin codebase. This allows you to use Firebase Analytics in a cross-platform manner, enabling you to track analytics events and user interactions across both iOS and Android platforms within your KMP project.

@akfpnd
Copy link

akfpnd commented Jun 4, 2024

Why? It's created by the developer for each project and stored inside the application or somewhere. This is quite normal.

Exiting native code base we have all written with native Firebase SDK and google-services.json using secret key creates multiple source of truths which violate our coding polices.

In a Kotlin Multiplatform (KMP) project targeting only iOS and Android, you can use google-services.json without secret keys by leveraging the Firebase Analytics SDK provided by the official libraries. Additionally, you can write expect/actual implementations to integrate the Firebase Analytics SDK into your shared Kotlin codebase. This allows you to use Firebase Analytics in a cross-platform manner, enabling you to track analytics events and user interactions across both iOS and Android platforms within your KMP project.

I was thinking about it, but it creates more boilerplate code to maintain I was hoping some simpler solution exists.

Hope it will become part of firebase-kotlin-sdk soon.

@DenisPopkov
Copy link
Author

@atonamy, for my enterprise project, using secret keys was a good solution because we only have Firebase Analytics and Crashlytics in our project. I think it's a quite good solution, but it might not be for some other projects.

@BasBuijsen
Copy link
Contributor

I am working on an implementation of this within this project. I created a PR for it so if it is accepted then it will be available soon. #525

@BasBuijsen
Copy link
Contributor

Its merged so in the next version it will be available 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API coverage Request for missing APIs
Projects
None yet
Development

No branches or pull requests

4 participants