Android (Kotlin) SDK
Native Android SDK for JustAnalytics mobile app monitoring.
Installation#
The JustAnalytics Android SDK is distributed via GitHub Packages. This requires a GitHub personal access token with read:packages scope. We plan to migrate to Maven Central in the future.
Setup (one-time)#
- Create a GitHub personal access token at github.com/settings/tokens with
read:packagesscope - Add to your
~/.gradle/gradle.properties:gpr.user=YOUR_GITHUB_USERNAME gpr.key=YOUR_GITHUB_TOKEN
Gradle (Kotlin DSL)#
// build.gradle.kts
repositories {
mavenCentral()
google()
maven {
url = uri("https://maven.pkg.github.com/specifiedcodes/justanalyticstech")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
// build.gradle.kts (app)
dependencies {
implementation("app.justanalytics:android-sdk:0.1.1")
}
Gradle (Groovy)#
// build.gradle
repositories {
mavenCentral()
google()
maven {
url = uri("https://maven.pkg.github.com/specifiedcodes/justanalyticstech")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
// build.gradle (app)
dependencies {
implementation 'app.justanalytics:android-sdk:0.1.1'
}
Why GitHub Packages?
The JustAnalytics Java and Android SDKs are currently distributed via GitHub Packages rather than Maven Central. This gives us faster release cycles and simpler CI/CD automation. We plan to publish to Maven Central in the future for convenience.
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