Android SDK
The GrowthRail Android SDK is the native Kotlin counterpart to the React Native SDK. It provides attribution and referral APIs, automatic referral UI (trigger, banner, and dashboard), and deep-link handling for View-system apps.
Installation
The SDK is published to Maven Central as two artifacts. Prefer the full growthrail artifact unless you are building a custom UI.
repositories {
google()
mavenCentral()
}
dependencies {
// Complete SDK: core APIs plus the native referral UI.
implementation("dev.growthrail:growthrail:0.1.1")
// Or, for a headless/custom UI integration:
// implementation("dev.growthrail:growthrail-core:0.1.1")
}0.1.1. Local development can use 0.1.0-SNAPSHOT from Maven Local.| Artifact | Use when |
|---|---|
dev.growthrail:growthrail | Full SDK including the View overlay host. Depends on growthrail-core transitively. |
dev.growthrail:growthrail-core | Attribution and referral APIs only — you render your own UI and collect GrowthRail.state. |
Configuration
Call GrowthRail.initialize once in your Application class. Use a publishable mobile key; never embed a server secret in the APK.
import android.app.Application
import dev.growthrail.sdk.GrowthRail
import dev.growthrail.sdk.GrowthRailAppearance
import dev.growthrail.sdk.GrowthRailConfiguration
import dev.growthrail.sdk.GrowthRailTheme
class ExampleApplication : Application() {
override fun onCreate() {
super.onCreate()
GrowthRail.initialize(
this,
GrowthRailConfiguration(
projectSecretKey = "sk_your_publishable_mobile_key",
appearance = GrowthRailAppearance.DARK,
theme = GrowthRailTheme(primaryColor = "#2563eb"),
debug = BuildConfig.DEBUG,
),
)
}
}Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
projectSecretKey | string | — | Required Publishable mobile key (sk_...). |
apiUrl | string? | production API | Override for staging or local API testing. |
appearance | LIGHT | DARK? | system | Preferred appearance for automatic UI. |
theme.primaryColor | string? | campaign / #2563eb | Hex primary color for trigger and dashboard chrome. |
disableTriggerButton | boolean | false | Never show the automatic floating/edge trigger. |
userId | string? | null | If set, identifies the user automatically after bootstrap. |
debug | boolean | false | Verbose logging. Disable in production. |
cookieDomain and autoPageTrack exist for React Native source compatibility and have no effect on Android.Automatic UI
With the full growthrail artifact, attach the overlay after setContentView. The host renders the server-configured trigger, new-user banner, and referral dashboard.
import dev.growthrail.sdk.ui.GrowthRailOverlay
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
GrowthRailOverlay.attach(this)
}It is safe to call attach more than once; it returns the existing host. You can also place GrowthRailHostView as the top-most child of a root FrameLayout.
| Field | Values | Behavior |
|---|---|---|
trigger.displayMode | floating | edge | none | Circle inset trigger, flush edge tab, or hidden. Also respect disableTriggerButton. |
trigger.position | bottom-right, bottom-left, top-right, top-left | Corner placement for the trigger. |
modal.componentType | modal | drawer | Centered card over a dimmed backdrop, or bottom sheet with a drag handle (max ~90% height). |
banner.position | center-top, center-bottom, left-*, right-* | New-user promotional banner placement after attributed install/open. |
User Management
Call initAppUser after authentication with a stable app user ID. Any attribution captured from an incoming link is bound automatically.
lifecycleScope.launch {
val user = GrowthRail.initAppUser(userId)
val referralLink = GrowthRail.getReferralLink()
val attributionToken = GrowthRail.getAttributionToken()
}GrowthRail.state is a StateFlow with isInitialized, isUserReady, currentUser, isLoading, error, referral fields, trigger visibility, banner state, and dashboard state.
Common APIs
| Need | API |
|---|---|
| Identify user | suspend GrowthRail.initAppUser(userId) or identify(userId) |
| Open / close dashboard | showReferralDashboard(options), hideReferralDashboard() |
| Incoming attribution | getReferralTrackingId(), getAttributionToken(), getCapturedReferralCode() |
| Current referral data | getReferralLink(), getReferralCode() |
| Track a non-standard source | suspend trackReferral(referralCode, rewardEventName) |
| Dismiss banner | dismissBanner() |
| Custom UI | Collect GrowthRail.state; optionally embed ReferralDashboard / TriggerButton |
Dashboard options override
GrowthRail.showReferralDashboard(
ReferrerModalOptions(
title = "Invite Friends",
description = "Share your link and earn rewards.",
componentType = ReferralDashboardPresentation.DRAWER,
appearance = GrowthRailAppearance.DARK,
theme = GrowthRailTheme(primaryColor = "#2563eb"),
)
)Deep Linking
Declare a custom scheme or verified App Link, then forward intents to GrowthRail. The handler returns false for URLs that do not contain a non-empty referralCode query parameter.
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="your-app" />
</intent-filter>
</activity>override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent.data?.let(GrowthRail::handleDeepLink)
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
intent.data?.let(GrowthRail::handleDeepLink)
}On first launch the SDK checks Google Play Install Referrer, then uses the same privacy-preserving match-link fallback as React Native.
adb shell am start -a android.intent.action.VIEW -d 'your-app://open?referralCode=TEST123'Complete Example
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
GrowthRailOverlay.attach(this)
intent.data?.let(GrowthRail::handleDeepLink)
lifecycleScope.launch {
GrowthRail.initAppUser("user_123")
}
findViewById<Button>(R.id.invite).setOnClickListener {
GrowthRail.showReferralDashboard()
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
intent.data?.let(GrowthRail::handleDeepLink)
}
}Differences from React Native
| Feature | React Native | Android (Kotlin) |
|---|---|---|
| Distribution | npm (@growth-rail/react-native) | Maven Central AARs |
| Entry point | GrowthRailProvider + hooks | GrowthRail.initialize + GrowthRailOverlay.attach |
| Storage | AsyncStorage | SharedPreferences-backed storage |
| UI | React Native components | View-system overlay host |
| Modal vs drawer | Custom animated views | Centered dialog vs bottom-gravity sheet |