Kotlin / Android
The OpenPanel Kotlin SDK allows you to track user behavior in your Kotlin and Android applications.
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.
Installation
This package is not yet published. So you cannot install it with gradle yet.
Step 1: Add Dependency
Add the OpenPanel SDK to your project's dependencies:
Step 2: Initialize
First, import the SDK and initialize it with your client ID:
Configuration Options
context
- Type:
Context - Required: Yes
- Description: Android
Contextused for initializing the SDK.
Options
Common options
apiUrl- The url of the openpanel API or your self-hosted instanceclientId- The client id of your applicationclientSecret- The client secret of your application (only required for server-side events)filter- A function that will be called before sending an event. If it returns false, the event will not be sentdisabled- If true, the library will not send any events
Additional Kotlin-specific options:
filter- A function that will be called before tracking an event. If it returns false, the event will not be trackeddisabled- Set totrueto disable all event trackingautomaticTracking- Set totrueto automatically track app lifecycle eventsverbose- Set totrueto enable verbose logging
Filter Example
Usage
Tracking Events
To track an event:
Identifying Users
To identify a user:
Setting Global Properties
To set properties that will be sent with every event:
Incrementing Properties
To increment a numeric property on a user profile:
Decrementing Properties
To decrement a numeric property on a user profile:
Clearing User Data
To clear the current user's data:
Advanced Usage
Custom Event Filtering
You can set up custom event filtering:
Disabling Tracking
You can temporarily disable tracking:
Automatic Tracking
The SDK can automatically track app lifecycle events if automaticTracking is set to true. This will track "app_opened" and "app_closed" events:
System Information
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)
Thread Safety
The OpenPanel SDK is designed to be thread-safe. You can call its methods from any thread without additional synchronization.
Support
For any issues or feature requests, please file an issue on our GitHub repository.