MyAppAffiliate

Android SDK

Kotlin SDK for Android apps. Same two-call surface as iOS — and on Android the first call can be zero lines of Kotlin.

Set this up with your AI coding agent
Integrate MyAppAffiliate into my project.

Documentation (read these first, they are the source of truth):
- Page: https://docs.myappaffiliate.com/sdk-android.md
- Full docs index: https://docs.myappaffiliate.com/llms.txt

Task: Add the MyAppAffiliate Android SDK to my app: add the Gradle dependency, put the API key in the manifest so the SDK self-starts, and identify the user with the same id my billing provider reports.

Rules:
- Follow the documented API exactly — no invented method names, endpoints, parameters or field names.
- Match the conventions already used in my codebase.
- Ask me for my SDK key instead of guessing, and never hard-code it — read it from config/environment.
- Do NOT set an API base URL anywhere. Every SDK compiles the production host in; a staging or self-hosted host belongs in a build setting, not in code.
- Tell me afterwards which steps I still have to do by hand (dashboard settings, capabilities, webhook configuration).

Install (Gradle)

Kotlin
// build.gradle.kts (module)
dependencies {
  implementation("com.myappaffiliate:sdk:0.2.0")
}

A plain Kotlin library — no Play Services dependency, minSdk 24.

1. Start it — from the manifest

Paste your key into the manifest and the SDK starts itself when the process does. No Application subclass, no onCreate edit:

XML
<application>
  <meta-data android:name="com.myappaffiliate.API_KEY" android:value="pk_live_…" />
</application>

Prefer code — a key from a secret store, a per-flavour value? Call it yourself and skip the meta-data:

Kotlin
import com.myappaffiliate.sdk.MyAppAffiliate
 
class App : Application() {
  override fun onCreate() {
    super.onCreate()
    MyAppAffiliate.start(this, apiKey = "pk_live_…")
  }
}

You never pass an API URL — the host is compiled in.

2. Identify the user

Call this once you know who the user is. The id must be the same string your billing provider reports back to us — RevenueCat's logIn(...) id, Adapty's customer user id, Superwall's app user id, or your Paddle/Stripe custom data. See Billing & Webhooks.

Kotlin
MyAppAffiliate.identify(userId)

That's the whole integration. There is no third step — in particular, you do not need to set an affiliate_id subscriber attribute anywhere; attribution joins on the user id.

Optional

App Links — if links open your app directly, hand the SDK the Intent. A null data URI is a safe no-op, so the call needs no guard:

Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  MyAppAffiliate.attribute(intent)
}
 
override fun onNewIntent(intent: Intent) {
  super.onNewIntent(intent)
  MyAppAffiliate.attribute(intent)
}

Creator codes — a "Got a code?" field. Works with no deep-link setup at all:

Kotlin
MyAppAffiliate.applyCode("LUMI")

Read the attribution for your own UI or analytics:

Kotlin
val affiliateId = MyAppAffiliate.attributedAffiliateId()  // String?

Play Install Referrer — optional extra precision for Play Store installs. Add com.android.installreferrer:installreferrer:2.2, read the referrer string on first launch, and pass it through:

Kotlin
MyAppAffiliate.applyInstallReferrer(referrerString)

Without it, a store install still gets a deferred match from start, and creator codes never needed it.

Staging or self-hosted API, and debug logging — in the manifest:

XML
<meta-data android:name="com.myappaffiliate.API_BASE_URL" android:value="https://staging.example.com" />
<meta-data android:name="com.myappaffiliate.DEBUG" android:value="true" />

…or in code: MyAppAffiliate.start(this, apiKey, MyAppAffiliate.Options(apiBaseUrl = …, debug = true)). To turn auto-start off entirely, set com.myappaffiliate.AUTO_START to false.

On logout or a data-erasure request:

Kotlin
MyAppAffiliate.reset()

What start does for you

  • Generates and persists a device id in SharedPreferences — no advertising id, no fingerprinting.
  • Retries a referral an earlier launch captured but failed to send.
  • On a fresh install with no link to go on, asks the API for a deferred match.

All network calls run on a single background thread and are silent-safe: failures return false/null and never crash or block the host app.

App Links need a verified assetlinks.json — see Go-Live. Skip it and creator codes still work.

API

CallPurpose
MyAppAffiliate.start(context, apiKey)Start once at launch (or let the manifest do it)
MyAppAffiliate.identify(userId)Bind your user id to the attribution
MyAppAffiliate.attribute(intent)Claim a referral from an App Link
MyAppAffiliate.applyCode(code)Creator-code entry
MyAppAffiliate.applyInstallReferrer(referrer)Play Install Referrer payload
MyAppAffiliate.attributedAffiliateId()The attributed affiliate id (or null)
MyAppAffiliate.reset()Clear all persisted SDK state