RiftRift

Mobile SDK

Android SDK

Native Kotlin SDK for click tracking and attribution. Built with Rust and compiled to a Kotlin library via UniFFI.

Installation

1

Add the library

Download the latest rift-android-sdk-*.tar.gz from GitHub Releases. Extract into your project and add it as a module:

// settings.gradle.kts
include(":rift-sdk")
project(":rift-sdk").projectDir = file("libs/android")

// app/build.gradle.kts
dependencies {
    implementation(project(":rift-sdk"))
}
2

Initialize

You need a publishable key to initialize the SDK.

import ink.riftl.sdk.*

// Initialize once (e.g., in Application.onCreate).
val rift = RiftSdk(publishableKey = "pk_live_YOUR_KEY")

// Or point to a self-hosted instance:
val rift = RiftSdk(publishableKey = "pk_live_YOUR_KEY", baseUrl = "https://api.yourcompany.com")

Click Tracking

3

Record a click

If your app opens Rift links internally, record the click:

suspend fun trackClick(linkId: String) {
    try {
        val result = rift.click(linkId = linkId)
        Log.d("Rift", "Platform: ${result.platform}")
        Log.d("Rift", "Deep link: ${result.androidDeepLink}")
    } catch (e: RiftError) {
        Log.e("Rift", "Click error", e)
    }
}

Post-Install Attribution

4

Read link ID from install referrer

When a user clicks a Rift link on Android, the link ID is appended to the Play Store URL as rift_link=<link_id> in the install referrer. Read it and resolve the link after install:

import com.android.installreferrer.api.*

fun checkDeferredDeepLink() {
    val client = InstallReferrerClient.newBuilder(this).build()
    client.startConnection(object : InstallReferrerStateListener {
        override fun onInstallReferrerSetupFinished(code: Int) {
            if (code == InstallReferrerResponse.OK) {
                val referrer = client.installReferrer.installReferrer
                val linkId = parseReferrerLink(referrer)
                if (linkId != null) {
                    resolveAndAttribute(linkId)
                }
            }
            client.endConnection()
        }
        override fun onInstallReferrerServiceDisconnected() {}
    })
}
5

Resolve and report attribution

suspend fun resolveAndAttribute(linkId: String) {
    // Report attribution
    try {
        val success = rift.reportAttribution(
            linkId = linkId,
            installId = getInstallId(),
            appVersion = BuildConfig.VERSION_NAME
        )
        Log.d("Rift", "Attribution reported: $success")
    } catch (e: RiftError) {
        Log.e("Rift", "Attribution error", e)
    }

    // Fetch link data for navigation (public endpoint, no auth needed)
    val url = URL("https://api.riftl.ink/r/$linkId")
    val conn = url.openConnection() as HttpURLConnection
    conn.setRequestProperty("Accept", "application/json")
    val link = JSONObject(conn.inputStream.bufferedReader().readText())

    link.optString("android_deep_link")?.let { deepLink ->
        handleDeepLink(deepLink)
    }
}
Note: The SDK methods are suspend functions — call them from a coroutine scope.

API Reference

RiftSdk(publishableKey, baseUrl?)

Constructor. The publishableKey parameter is required. The baseUrl is optional (defaults to https://api.riftl.ink).

Methods

MethodReturnsDescription
click(linkId)ClickResultRecords a click and returns link data.
reportAttribution(linkId, installId, appVersion)BooleanReports an install attribution.

Free functions

FunctionDescription
parseReferrerLink(referrer)Extracts link ID from rift_link=<link_id> referrer string. Returns null if not found.