Android SDK (Kotlin)
Add affiliate install and purchase attribution to your Android app with a lightweight Kotlin library.
Prerequisites
- Android 5.0 (API level 21) or later
- Kotlin 1.8 or later
- An Appfiliate account with an App ID and API Key (available at app.appfiliate.io)
Step 1: Add the dependency
First, add the JitPack repository to your project-level settings.gradle.kts:
settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}Then add the Appfiliate SDK to your app-level build.gradle.kts:
build.gradle.kts
dependencies {
implementation("com.github.appfiliate:appfiliate-android-sdk:1.0.0")
}Sync your project and the dependency will be resolved from JitPack.
Step 2: Configure and track install
Initialize the SDK as early as possible in your app lifecycle. Replace the placeholder values with the App ID and API Key from your Appfiliate dashboard.
Application class (recommended)
MainApplication.kt
import android.app.Application
import com.appfiliate.sdk.Appfiliate
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
Appfiliate.configure(this, appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
Appfiliate.trackInstall(this)
}
}Register your Application class
Make sure your custom Application class is declared in
AndroidManifest.xml:AndroidManifest.xml
<application
android:name=".MainApplication"
...>Main Activity (alternative)
MainActivity.kt
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.appfiliate.sdk.Appfiliate
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Appfiliate.configure(this, appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
Appfiliate.trackInstall(this)
}
}Step 3: Track purchases (optional)
To attribute revenue to affiliates, call trackPurchase() after every successful Google Play Billing purchase.
BillingManager.kt
import com.appfiliate.sdk.Appfiliate
import com.android.billingclient.api.Purchase
fun handlePurchase(purchase: Purchase) {
if (purchase.purchaseState == Purchase.PurchaseState.PURCHASED) {
Appfiliate.trackPurchase(
context = this,
productId = purchase.products.first(),
revenue = 9.99,
currency = "USD",
transactionId = purchase.orderId ?: ""
)
// Acknowledge or consume the purchase...
}
}Important notes
Install Referrer attribution
On Android, the Appfiliate SDK uses the Google Play Install Referrer API for deterministic attribution. This is the only external dependency the SDK relies on. No device identifiers or advertising IDs are required.
trackInstall()is safe to call on every app launch. It only fires once per install.trackPurchase()should be called after every successful in-app purchase.- The SDK is under 200 KB. The only external dependency is the Google Play Install Referrer library.
- Works alongside any other analytics or attribution provider.