Android (Kotlin) SDK
Native Android SDK for JustAnalytics mobile app monitoring.
Installation#
Gradle (Kotlin DSL)#
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
mavenCentral()
maven("https://jitpack.io")
}
}
// build.gradle.kts (app)
dependencies {
implementation("com.github.specifiedcodes.justanalytics-java:justanalytics-core:0.1.0")
}
Gradle (Groovy)#
// settings.gradle
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
// build.gradle (app)
dependencies {
implementation 'com.github.specifiedcodes.justanalytics-java:justanalytics-core:0.1.0'
}
Quick Start#
// Application.kt
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
JustAnalytics.init(
context = this,
siteId = "YOUR_SITE_ID",
apiKey = "YOUR_API_KEY",
environment = "production"
)
}
}
Screen Tracking#
Jetpack Compose#
@Composable
fun HomeScreen() {
TrackScreen("Home")
Column {
Text("Home Screen")
}
}
Activity / Fragment#
class HomeActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
JustAnalytics.trackScreen("Home")
}
}
Error Tracking#
// Automatic crash reporting is enabled by default
// Manual capture
try {
riskyOperation()
} catch (e: Exception) {
JustAnalytics.captureException(e, mapOf("module" to "payments"))
}
Custom Events#
JustAnalytics.trackEvent("purchase_complete", mapOf(
"product" to "Pro Plan",
"price" to 49.99,
"currency" to "USD"
))
Performance Tracing#
val result = JustAnalytics.startSpan("load-feed") { span ->
span.setAttribute("feed.type", "home")
val data = api.fetchFeed()
span.setAttribute("feed.count", data.size)
data
}
User Context#
JustAnalytics.setUser(
id = "user-123",
email = "alice@example.com",
name = "Alice"
)
Network Monitoring#
// OkHttp interceptor
val client = OkHttpClient.Builder()
.addInterceptor(JustAnalytics.okHttpInterceptor())
.build()
// Retrofit integration
val retrofit = Retrofit.Builder()
.client(client)
.baseUrl("https://api.example.com/")
.build()
ANR Detection#
The SDK automatically detects Application Not Responding (ANR) events on the main thread and reports them with full stack traces.
Requirements#
- Android API 24+ (Android 7.0)
- Kotlin 1.8+
- AndroidX