Android SDK Integration
Measure installs, in-app events and revenue from your Android app, and credit them to the affiliate or campaign that brought the user.
Overview
The SDK needs Android 5.0 (API 21) or later and works from Kotlin and Java. It reports the install once, using the Google Play install referrer, any deep-link click and the advertising ID. It sends each event with its own ID so a retry is never counted twice, and saves events on the device until they are delivered.
Before you start, add your app under Mobile Apps in the dashboard and open its SDK & Links tab. You need the app key, the SDK signing secret and your tracking domain. Mobile Apps is enabled per account: contact support if you do not see it.
Install
Add JitPack to settings.gradle:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
} Then add the SDK to your app module:
dependencies {
implementation 'com.github.affclix:affclix-android-sdk:1.0.2'
} The ProGuard / R8 rules ship with the library, so there is nothing to add.
Start the SDK
// Application.onCreate()
AffclixSDK.init(application, AffclixConfig(
appKey = "YOUR_APP_KEY",
appSecret = BuildConfig.AFFCLIX_APP_SECRET,
trackingDomain = "track.yourbrand.com",
debug = BuildConfig.DEBUG,
callbacks = AffclixCallbacks(
onDeepLinkResolved = { r -> route(r.deepLinkValue) },
onError = { e -> Log.e("Affclix", "error: ${e.message}") }
)
)) Inject the signing secret at build time and keep it out of source control.
In-App Events
Send your own event names. Which campaign goal each one books is set under Settings → Events, so it can change without an app release.
AffclixSDK.logRegistration("google_oauth")
AffclixSDK.logEvent("product_viewed", mapOf("product_id" to "prod_123")) An event with no goal is still recorded, but no conversion is created for it.
Revenue
AffclixSDK.logPurchase(4999.0, "INR", "ORD-001")
// Google Play purchase: validated when your Play service account is in Settings
AffclixSDK.logPlayPurchase(productId = p.products[0], purchaseToken = p.purchaseToken,
revenue = 4.99, currency = "USD", orderId = p.orderId, eventToken = "purchase")
AffclixSDK.logAdRevenue(network = "applovin", revenue = 0.0021, adFormat = "rewarded") Always send your order ID: a second conversion with the same ID is rejected, so a repeated call is not paid twice.
Deep Links
Pass the intent from every entry activity. The SDK keeps the click, and later events are credited to it.
AffclixSDK.handleDeepLink(intent, object : DeepLinkCallback {
override fun onDeepLinkResolved(result: DeepLinkResult) {
// result.clickId, result.deepLinkValue, result.isDeferredDeepLink
}
}) Branded links look like https://your-tracking-domain/l/your.application.id?click_id=…&deep_link_value=…. With the app installed and App Links verified, the app opens on the link. Otherwise the user goes to Google Play, and the link reaches onDeepLinkResolved on first open with isDeferredDeepLink set.
To verify App Links, add your signing certificate's SHA-256 under Settings → Deep Links and add this to your activity:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="your-tracking-domain" android:pathPrefix="/l/" />
</intent-filter> Your app can also share one link with its iOS version: choose it under Settings → Deep Links, and each device goes to its own store.
Consent & Deletion
AffclixSDK.setConsentData(
isUserSubjectToGDPR = true,
hasConsentForDataUsage = false,
hasConsentForAdsPersonalization = false
)
AffclixSDK.grantConsent() // deliver events held while consent was pending
AffclixSDK.revokeConsent() // stop tracking, forget IDs on the device
AffclixSDK.requestDataDeletion() // erase this device's data When a user refuses ad data use, their device ID is not used for matching. Set enableTCFDataCollection to read consent from your CMP instead.
requestDataDeletion removes the device's data from mobile attribution and clears its identifiers on the device. Conversions already credited to an affiliate stay in your campaign reports.
Uninstall Tracking
Add your Firebase service-account JSON under Settings → Uninstall Tracking, then register the token:
class PushService : FirebaseMessagingService() {
override fun onNewToken(token: String) = AffclixSDK.setPushToken(token)
override fun onMessageReceived(msg: RemoteMessage) {
if (AffclixSDK.isUninstallCheck(msg.data)) return
// your own messages
}
}
// and once at startup:
FirebaseMessaging.getInstance().token.addOnSuccessListener { AffclixSDK.setPushToken(it) } Test Your Integration
- Add your device's advertising ID under the Test Devices tab. Install and event requests then appear in Live Test Events within seconds, with anything missing listed beside them.
- Test devices can install repeatedly, but they never create conversions. To check a real conversion, remove the device and click a campaign's tracking link.
- Check the Setup checklist on SDK & Links. It shows Ready once your app is sending data and a campaign is linked.
The Play install referrer only carries a click for an app installed from Google Play. An APK installed directly reports no click, so test that path from a Play internal testing track.
Troubleshooting
| What you see | What to check |
|---|---|
INVALID_SIGNATURE | The appSecret does not belong to this app key. Copy it again from SDK & Links. |
APP_ID_MISMATCH | The app's applicationId differs from the package name registered in the dashboard. |
| Install shows as organic | The app was installed outside Google Play, was opened before the deep link, or the campaign has an older destination URL. |
| Event recorded, no conversion | Map the event to a goal under Settings → Events, and check that goal is on the campaign. |
| A second install is not counted | Expected: reinstalling on the same device keeps the first install's attribution during the re-attribution window. |
| Later events became organic | requestDataDeletion was called: the device starts again as a new user. |
| Conversions appear a little late | Bursts of events on one click are limited per minute and delivered shortly afterwards. |
Was this article helpful?
Help us improve this article. What kind of issue did you find?