Kotzilla SDK API
This page describes Kotzilla SDK API and provides examples of how to use it to track events, manage session data, and capture performance metrics in your application.
The Kotzilla SDK supports five app types: Android, Android with Compose, Composable Multiplatform (CMP), Kotlin Multiplatform (KMP), and SDK Library for Android. API usage differs slightly depending on the app type. See setup instructions below.
Android, Android with Compose, and CMP
For these app types, you can initialize the SDK directly in your Koin setup using the analytics()
function:
import io.kotzilla.sdk.KotzillaSDK
...
startKoin {
androidContext(this@MyApplication)
analytics()
...
}
The SDK automatically uses the configuration values from your kotzilla.json file (API key, version, etc.). Once initialized, you can directly use the KotzillaSDK API to track events, manage sessions, or capture performance metrics.
KMP and SDK Library for Android
For these app types, manual setup is required. Create a KotzillaCoreSDK instance and attach it to your Koin configuration (i.e, in commonMain for KMP):
import io.kotzilla.sdk.KotzillaCoreSDK
...
val sdk = KotzillaCoreSDK
.setup(apiToken = "your-api-key", version = "your-version")
.attachKoin()
.connect()
Replace any call to KotzillaSDK in examples below with your sdk instance. Use this setup from your shared/common code (i.e, commonMain) for KMP or from your library module for SDK Library integrations.
Logging Messages
You can add custom log messages to your app's timeline to provide additional context and track important events using the log
function. This is useful for capturing information about specific actions or states in your app.
- Function:
KotzillaSDK.log(message: String)
Example:
KotzillaSDK.log("a message ...")
This will add the message to your timeline, helping you track events in the app.
Capture crashes
To capture exceptions and add them to your timeline for later debugging, you can log them using the log
function, along with the exception.
- Function:
KotzillaSDK.log(message: String, exception: Throwable)
Example:
KotzillaSDK.log("an error occurred", exception)
This will record both the message and exception, making it easier to debug issues that happen in production.
Trace code performance
To measure the performance of specific code blocks, you can use the trace
function. This allows you to benchmark the execution time of certain operations and track their performance within your app.
- Function:
KotzillaSDK.trace(name: String, block: () -> Unit)
Example:
KotzillaSDK.trace("my_code_block") {
// My code to benchmark here ...
myComponent.MyHeavyCall()
}
This will track the performance of the specified code block and record the execution time in your timeline.
Add session properties
You can add custom properties to the current session to enrich the context of your app's data. This can include anything from user preferences to current app settings.
- Function:
KotzillaSDK.setProperties(vararg properties: Pair<String, Any>)
Example:
KotzillaSDK.setProperties(
"my_string" to "a_string",
"my_int" to 1,
"my_double" to 1.0,
"my_bool" to true,
)
This will add the provided properties to the session data, helping you track custom context during a user's session.
Set user Id properties
To track sessions for specific users, you can set a unique user ID. This allows you to correlate the session data with a particular user, enabling more granular analysis.
- Function:
KotzillaSDK.setUserId(userId: String)
Example:
KotzillaSDK.setUserId("user_123")
This will associate the current session with the specified user ID and add it to the session data for tracking purposes.