KMM Analytics Tech Blog

Amrit Pandey
Cox Auto Tech Blog
Published in
3 min readJul 29, 2021

With a growing product, it’s always difficult and sometimes painful to maintain two separate codebases; one for Android and another for iOS. Recently, our vAuto mobile group began researching ways to ease the pain. You can check this story for how we evolved our analytics planning process.

In this document, we will talk about how we are exploring KMM at vAuto. There are many hybrid platforms available now for mobile development in the likes of React Native, Xamrin, Flutter, KMM. So Why KMM?

First, this fits our desire to create a shared business logic component with low risk. Beyond that, through KMM we can leverage cool features of the modern-day language Kotlin. Ramping up the team in KMM require less effort than other cross-platform solutions, as Android developers have knowledge of Kotlin, while iOS developers can ramp up quickly as Kotlin syntaxes are similar to Swift.

About KMM

KMM is an SDK for cross-platform mobile development provided by JetBrains. It uses the multiplatform capabilities of Kotlin and includes various tools and features designed to make the end-to-end experience of building mobile cross-platform applications as enjoyable and efficient as possible.

The Android and iOS versions of an application often have much in common, but they can also differ significantly — especially in terms of their UI — from subtle variations in scrolling behavior to completely divergent navigation logic. At the same time, the application’s business logic, including such features as data management, analytics, and authentication, is often identical. That’s why it’s natural to share some parts of an application across platforms while keeping other parts separate.

With KMM, we only need to write platform-specific code where it’s necessary, especially when dealing with the UI of our app. Business logic, however, is developed once in a common module. Then each platform consumes the code developed in KMM as though it were an SDK, for example, to implement a common analytics module, we will create an interface in KMM, with the dependency of analytics SDK to be consumed in each platform.

High Level design

In the above design before KMM, our mobile apps don’t know anything about each other. They have their own analytics code which will interact with analytics SDK. After integrating KMM, all analytics code is now moved to a KMM library written in Kotlin. Now both apps need to adhere to the common definition provided by KMM. So many of the possible errors like different parameter values of events, different event names etc. are eliminated.

A common codebase here allows us to streamline our analytics planning and analysis. Logging analytics on Android and iOS can easily yield various results. One platform could be logging an event called “Inventory Vehicle” with a status. The other platform could be logging an event called “inventoryVehicle” without a status. Through the KMM code, we can enforce a strict standard of event names and parameters to be logged with each.

Wind-up

It is always good to have some shared modules in your app. Networking and analytics are commonly used modules in almost every app. This will mitigate the risk of having different business logic written on different platforms. Module written in KMM is faster than other hybrid technologies. Android can integrate KMM code as a Kotlin dependency whereas iOS integrates as a framework (with Obj-C code). When the app’s run they don’t require any bridge (like JSbridge in react native).

In the next article, we will talk about compiling and distributing KMM code on both iOS and Android platforms.

DISCLOSURE STATEMENT: Opinions are those of the individual author. Unless noted otherwise in this post, Cox Automotive is not affiliated with, nor endorsed by, any of the companies mentioned. All trademarks and other intellectual property used or displayed are property of their respective owners.

--

--