Hi all, can we use firebase analytic on a KMM project?
b
Hi all, can we use firebase analytic on a KMM project?
m
I think there is a third party lib...
k
Generally speaking, analytics calls consist of an event name and a map of key/value pairs. We usually just write a Kotlin interface to call from shared code and pass in a simple Swift implementation on app start. Taking a quick look at that firebase lib, I don’t think it has analytics.
2
b
@mbonnin thanks for sharing
@kpgalligan so you basically used
expect/actual
? i think it’s the best option
when logging error messages what event name/params do you usually use
k
I rarely use
expect/actual
. Depends on the situation. I’d just have a function defined in common and pass in the implementation on app start.
expect/actual
is rigid and not useful in this case.
So, for Firebase the call to log an event is this in Swift
Copy code
class func logEvent(_ name: String, parameters: [String : Any]?)
I assume similar on Android.
I’d just have an init call in common code that takes a function as a param:
Copy code
fun initAppStuff(logEvent: (String, Map<String, Any>)->Unit)
Something like that. On iOS, call that in the AppDelegate (or the new equivalent thing I don’t remember). Similar thing on Android. Call in Application.onCreate. On both, have that function call the actual Firebase method.
b
I see, thanks for sharing
1198 Views