GitLiveApp / firebase-kotlin-sdk

A Kotlin-first SDK for Firebase
https://gitliveapp.github.io/firebase-kotlin-sdk/
Apache License 2.0
979 stars 148 forks source link

Add Firebase Analytics for [KMP] #517

Closed DenisPopkov closed 1 week ago

atonamy commented 3 weeks ago

Yes, we absolutely need it

DenisPopkov commented 3 weeks ago

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

atonamy commented 3 weeks ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

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 commented 3 weeks ago

@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 commented 3 weeks ago

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. https://github.com/GitLiveApp/firebase-kotlin-sdk/pull/525

BasBuijsen commented 1 week ago

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