The OpenPanel Kotlin SDK allows you to track user behavior in your Kotlin applications. This guide provides instructions for installing and using the Kotlin SDK in your project.
⚠️ This package is not yet published. So you cannot install it withgradle
Add the OpenPanel SDK to your project's dependencies:
dependencies {
implementation 'dev.openpanel:openpanel:0.0.1'
}First, import the SDK and initialize it with your client ID:
import dev.openpanel.OpenPanel
val op = OpenPanel.create(
context,
OpenPanel.Options(
clientId = "YOUR_CLIENT_ID",
clientSecret = "YOUR_CLIENT_SECRET"
))- Type:
Context - Required: Yes
- Description: Android
Contextused for initializing the SDK.
- Type:
OpenPanel.Options - Required: Yes
- Description: Configuration options for the SDK. Contains parameters for client ID, client secret, and other settings.
clientId: Required, your OpenPanel client ID.clientSecret: Optional, your OpenPanel client secret.apiUrl: Optional, custom API URL.waitForProfile: Optional, delays sending events until profile is set.filter: Optional, filters events before sending.disabled: Optional, disables event sending.automaticTracking: Optional, enables automatic tracking.verbose: Optional, enables verbose logging.
To track an event:
op.track("button_clicked", mapOf("button_id" to "submit_form"))To identify a user:
op.identify("user123", mapOf(
"firstName" to "John",
"lastName" to "Doe",
"email" to "john@example.com",
"customAttribute" to "value"
))To set properties that will be sent with every event:
op.setGlobalProperties(mapOf(
"app_version" to "1.0.2",
"environment" to "production"
))To create an alias for a user:
op.alias("user123", "john_doe")To increment a numeric property on a user profile:
op.increment("user123", "login_count", 1)To decrement a numeric property on a user profile:
op.decrement("user123", "credits", 5)To clear the current user's data:
op.clear()You can set up custom event filtering:
val op = OpenPanel(OpenPanel.Options(
clientId = "YOUR_CLIENT_ID",
filter = { payload ->
// Your custom filtering logic here
true // or false to filter out the event
}
))You can temporarily disable tracking:
val op = OpenPanel(OpenPanel.Options(
clientId = "YOUR_CLIENT_ID",
disabled = true
))The SDK can automatically track app lifecycle events if automaticTracking is set to true. This will track "app_opened" and "app_closed" events.
The SDK automatically gathers system information and adds it to the properties of every tracking event. This includes:
- OS details (e.g.,
os,os_version) - Device manufacturer, brand, and model (e.g.,
manufacturer,brand,model) - Screen resolution and DPI (e.g.,
screen_width,screen_height,screen_dpi) - App version (e.g.,
app_version,app_build_number) - Network details (e.g.,
wifi,carrier,bluetooth_enabled)
The OpenPanel SDK is designed to be thread-safe. You can call its methods from any thread without additional synchronization.
For any issues or feature requests, please file an issue on our GitHub repository.