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:

Groovy
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

Then add the SDK to your app module:

Groovy
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

Kotlin
// 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.

Kotlin
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

Kotlin
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.

Consent & Deletion

Kotlin
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:

Kotlin
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

  1. 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.
  2. 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.
  3. 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 seeWhat to check
INVALID_SIGNATUREThe appSecret does not belong to this app key. Copy it again from SDK & Links.
APP_ID_MISMATCHThe app's applicationId differs from the package name registered in the dashboard.
Install shows as organicThe app was installed outside Google Play, was opened before the deep link, or the campaign has an older destination URL.
Event recorded, no conversionMap the event to a goal under Settings → Events, and check that goal is on the campaign.
A second install is not countedExpected: reinstalling on the same device keeps the first install's attribution during the re-attribution window.
Later events became organicrequestDataDeletion was called: the device starts again as a new user.
Conversions appear a little lateBursts of events on one click are limited per minute and delivered shortly afterwards.
Rate this article
★★★★★
Thanks for rating!

Was this article helpful?