Hi guys, just wanted to ask about your KMM strateg...
# touchlab-tools
a
Hi guys, just wanted to ask about your KMM strategy around Analytics. Do you keep the analytics code to platform specific? or do you build a common class/module for them as well and then use that in the platform specific code? Thanks in advance
k
Analytics is one of the suggested use cases for shared code. The idea is to build a typed analytics api that can homogenize the strings sent to the native analytics sdks. So, say you wanted to send an event for somebody clicking the "more info" button on the sign up screen. of an app, you'd have
analyticsApi.signUpMoreInfoClicked()
(or whatever). Most analytics sdks take a string key and a map of values. Create an interface in
commonMain
that has methods like
sendEvent(key:String, data: Map<String, Any>)
, then from Android and iOS (or other platforms), pass in the specific SDK implementation. Then, from shared code, you can call that interface. Make a typed class that can centralize those calls, which ultimately calls the platform specific implementations.
❤️ 1
👍 1
It would be easier to explain with code. I should probably do a small blog post 🙂
❤️ 1
a
I I would love to read your post if whenever it comes out 😄
k
I keep signing myself up for posts. Should probably do them...
😆 1