Skip to main content

Read the Myket Install Referrer

The Myket Install Referrer SDK lets an Android app retrieve the referrer captured when the app's Myket detail page was opened, along with click and install-begin timestamps. See myketstore/referrer-sample for a complete runnable sample.

Text file for LLMs

Download llm.txt for an English summary of the API, setup, and key implementation notes.

Prerequisites​

  • The SDK is for Android apps and requires the Myket app to be installed.
  • Myket must have a versionCode of at least 1030. The SDK checks this and returns FEATURE_NOT_SUPPORTED if Myket is missing or older.
  • The sample uses SDK version ir.myket:referrersdk:1.0.3.
  • The sample project uses minSdk 21, compileSdk 37, targetSdk 36, and Java/Kotlin 17. These are the sample's build settings; check toolchain compatibility separately for your own project.

Add the repository and dependency​

Add the Myket Maven repository to dependencyResolutionManagement in settings.gradle.kts:

dependencyResolutionManagement {
repositories {
maven { setUrl("https://maven.myket.ir") }
google()
mavenCentral()
}
}

Then add the SDK dependency to dependencies in app/build.gradle.kts:

dependencies {
implementation("ir.myket:referrersdk:1.0.3")
}

Permission and package visibility​

The library declares these entries in its own manifest, and Android's manifest merger normally adds them to your app. Inspect the merged manifest; if necessary, add the following to your app's AndroidManifest.xml:

<uses-permission android:name="ir.mservices.market.INSTALL_REFERRER" />

<queries>
<package android:name="ir.mservices.market" />
</queries>

Read the install referrer​

startConnection begins connecting asynchronously. The SDK first tries AIDL and falls back to a Broadcast transport if that connection fails. Because reading through the fallback may block until a reply arrives or a timeout expires, call getInstallReferrer() on a background thread.

import ir.myket.referrersdk.api.InstallReferrerResponse
import ir.myket.referrersdk.api.InstallReferrerStateListener
import ir.myket.referrersdk.api.MyketReferrerClient
import java.util.concurrent.Executors

val client = MyketReferrerClient.newBuilder(context).build()
val executor = Executors.newSingleThreadExecutor()

client.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
if (responseCode != InstallReferrerResponse.OK) {
// Handle NOT_FOUND, DEVELOPER_ERROR, FEATURE_NOT_SUPPORTED,
// SERVICE_DISCONNECTED, or another error as appropriate.
client.endConnection()
executor.shutdown()
return
}

executor.execute {
try {
val details = client.getInstallReferrer()
val referrer = details.installReferrer
val clickTimeSeconds = details.referrerClickTimestampSeconds
val installBeginTimeSeconds = details.installBeginTimestampSeconds

// Attribute this install and persist the result in your app.
} catch (error: Exception) {
// Handle read failures and retry only when appropriate.
} finally {
client.endConnection()
executor.shutdown()
}
}
}

override fun onInstallReferrerServiceDisconnected() {
// If you still need the data, create a new client and reconnect.
}
})

Create a new client for each attempt; endConnection() closes the connection. Persist the result after reading it, and make attribution handling safe against duplicate processing.

Returned values​

getInstallReferrer() returns ReferrerDetails. Timestamps are Unix time in seconds; 0 means the corresponding time is unknown.

PropertyDescription
installReferrerThe referrer string captured from the app detail link; it may be empty.
referrerClickTimestampSecondsWhen the Myket app detail page was opened, in seconds.
installBeginTimestampSecondsWhen installation began, in seconds.

Connection response codes:

CodeConstantMeaning
0OKConnected; the referrer can be read.
6NOT_FOUNDNo referrer record was found for the calling app.
5DEVELOPER_ERRORThe caller is not authorized to read the requested record. Myket only returns data for a package owned by the caller's UID.
1FEATURE_NOT_SUPPORTEDMyket is missing, is older than the minimum version, or the service is unavailable.
-1SERVICE_DISCONNECTEDThe service disconnected or an unexpected error occurred.

Test with the sample project​

On a device with Myket installed:

  1. Open the sample app's detail page with a referrer value. Use the sample app page on Myket or this deep link:

    myket://details?id=ir.myket.referrersample&referrer=my-referrer

    Equivalent web link:

    https://myket.ir/app/ir.myket.referrersample?referrer=my-referrer

    Open it with ADB using:

    adb shell am start -a android.intent.action.VIEW -d "myket://details?id=ir.myket.referrersample&referrer=my-referrer"
  2. Install the app from Myket. Direct APK installation or sideloading does not test Myket's install-referrer flow.

  3. Launch the app and tap Fetch referrer. The sample displays install_referrer and the click/install-begin timestamps; unavailable timestamps are zero.

Release builds and R8/ProGuard​

The repository provides ./gradlew assembleDebug for a local build. If minification is enabled for your release build, add these rules to your app's ProGuard/R8 file so the AIDL interface is not removed or renamed:

-keep interface com.myket.installreferrer.** { *; }
-keep class com.myket.installreferrer.** { *; }
Important

Validate and store the referrer securely according to your app's needs. The SDK provides attribution data for installs through Myket; a sideloaded install or an install without a recorded referrer may return NOT_FOUND.