Deferred deep linking on Android with the Play Install Referrer API
How to carry a link through a Google Play install with the Play Install Referrer API: the referrer parameter, the Kotlin code to read it on first launch, how to test it on a testing track, and where it stops working.
On Android, deferred deep linking works by adding a referrer parameter to the Google Play link and reading it back with the Play Install Referrer API when the app first opens. Google Play keeps the value through the install and returns it unchanged, so the match is exact: no fingerprinting and no advertising ID. Put a short click ID in the referrer, not the whole link, and look the link up on your server.
This post shows how to build it yourself in Kotlin, how to test it, and what it can't do. If you already have it and it fails, see deferred deep link not working after install. For the idea itself, see what deferred deep linking is.
How the Play Install Referrer carries a link through the install
- Someone without the app taps your link. Your link server records the click and gives it an ID.
- The server redirects to Google Play with that ID in the
referrerparameter. - The person installs the app from that Play Store page.
- On first launch, the app asks the Play Store app for the install referrer and gets the same string back.
- The app sends the ID to your server, receives the link it belongs to, and opens that screen.
Nothing is guessed. The value in step 4 is the value from step 2, for that install on that device.
Step 1: add the referrer to the Play Store link
The parameter is called referrer, and its value must be URL-encoded because it usually holds its own key=value pairs:
https://play.google.com/store/apps/details?id=com.yourcompany.app&referrer=click_id%3Dclk_8fK2mQ%26utm_source%3Dnewsletter
Decoded, the referrer is click_id=clk_8fK2mQ&utm_source=newsletter. Three rules:
- Encode it once. A raw
&ends the referrer early and the rest is lost. - Keep it short. Send an ID and look up the path, parameters and campaign on your server. That also lets you change the destination later.
- Don't put personal data in it. The value passes through a URL and Google Play.
An install with no referrer returns utm_source=google-play&utm_medium=organic, so your code has to treat "no click ID" as normal.
Step 2: add the library
// app/build.gradle.kts
dependencies {
implementation("com.android.installreferrer:installreferrer:2.2")
}
Version 2.2 is the one in Google's documentation today. The old way, a broadcast receiver for com.android.vending.INSTALL_REFERRER, stopped working in March 2020. If a tutorial tells you to register a receiver, it's out of date.
Step 3: read the referrer on first launch
Connecting is asynchronous. Start the connection, read the value in the callback, then close it.
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerClient.InstallReferrerResponse
import com.android.installreferrer.api.InstallReferrerStateListener
fun readInstallReferrer(context: Context, onResult: (String?) -> Unit) {
val prefs = context.getSharedPreferences("install", Context.MODE_PRIVATE)
if (prefs.getBoolean("referrer_read", false)) return onResult(null)
val client = InstallReferrerClient.newBuilder(context).build()
client.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
val referrer = if (responseCode == InstallReferrerResponse.OK) {
runCatching { client.installReferrer.installReferrer }.getOrNull()
} else null // FEATURE_NOT_SUPPORTED or SERVICE_UNAVAILABLE
client.endConnection()
prefs.edit().putBoolean("referrer_read", true).apply()
onResult(referrer)
}
override fun onInstallReferrerServiceDisconnected() {
// The Play Store app went away mid-call. Try again on the next launch.
}
})
}
Google's documentation says the referrer is available for 90 days and doesn't change unless the app is reinstalled, and asks you to call the API only once, on the first run after install. That's what the saved flag is for.
Besides the string, ReferrerDetails gives you referrerClickTimestampSeconds (when the Play page was opened from your link) and installBeginTimestampSeconds (when the install started). The gap between them is useful: a click from last week followed by an install today may not deserve the same treatment as one from two minutes ago.
Step 4: turn the referrer into a screen
readInstallReferrer(applicationContext) { referrer ->
val clickId = referrer
?.let { Uri.parse("https://x/?$it").getQueryParameter("click_id") }
?: return@readInstallReferrer // organic install or already handled
// Ask your server which link this click belongs to
api.resolveClick(clickId) { link ->
pendingDeepLink = link.path // e.g. /product/42
openWhenReady()
}
}
Two details decide whether this feels right to the user:
- Wait for the app to be ready. The callback can arrive before your navigation graph exists or before the person has signed in. Store the pending link and act on it when both are done.
- Don't block the first screen on it. The Play Store usually answers quickly, but give the call a timeout (a few seconds) and carry on without the link if it doesn't.
What about React Native?
The library is Java, so a React Native app needs a native module. The community package react-native-play-install-referrer wraps it:
import { PlayInstallReferrer } from "react-native-play-install-referrer";
PlayInstallReferrer.getInstallReferrerInfo((info, error) => {
if (!error && info) console.log(info.installReferrer);
});
In an Expo project it needs a development or release build, not Expo Go.
How to test it
You can't test this with adb install or a sideloaded APK: there is no Play install, so there is no referrer. What works:
- Upload the build to a Play testing track. Internal testing is enough.
- On a phone signed in as a tester, uninstall the app.
- Open the full Play link with the
referrerparameter, by tapping it in a notes app or a chat message. - Install from that page, then open the app.
Check four things if the value doesn't arrive: the install came from that Play page and not from a search or the "My apps" list, the referrer was encoded once, the read happens on the very first launch, and the device has the Play Store app.
Where the Play Install Referrer stops working
- Other stores and sideloading. Installs from an APK file or another app store don't have a Play referrer. Some stores have their own referrer API; many have none.
- A broken chain. If the person leaves the Play page and installs later from a search, the referrer is normally the organic one.
- Reinstalls and updates. The value belongs to the install. An update keeps the old value, and after 90 days it's gone.
- iOS. The App Store has nothing like it. iOS needs signal matching or an opt-in clipboard match, explained in deferred deep linking on iOS without IDFA.
- The app is already installed. Then nothing is deferred: the link should open the app directly as a verified Android App Link.
Because of the first two, a complete setup needs a fallback when the referrer is missing, usually a match on signals such as IP address and device model inside a short time window, and it should tell the app which method matched.
FAQ
Is the Play Install Referrer API free, and does it need a permission?
It's free and part of Google Play. Your app doesn't ask the user for anything, and it doesn't read the advertising ID.
How long is the install referrer available?
Google's documentation says 90 days after install, and the value doesn't change unless the app is reinstalled.
Can I put the whole deep link in the referrer?
You can, if you encode it, but an ID is safer. Long values are easy to break with double encoding, and an ID lets you change or expire the link on the server.
Does the referrer work for installs outside Google Play?
No. It comes from the Play Store app. Sideloaded builds and other stores need their own mechanism or a signal-based fallback.
Does this replace Firebase Dynamic Links on Android?
It replaces the part that carried a link through the install. You still need a link server to record clicks and redirect, and App Links for people who already have the app.
What CodeOnAir does with it
CodeOnAir AppLinks does these steps for you. Each link builds the Play Store URL from your package name with referrer=click_id%3Dclk_… (plus the link's UTM values), the Android SDK reads the referrer on the first launch with a 3 second timeout, and the server returns the link. Your app gets it in one callback:
DeepLink.onLink(this) { link ->
// link.isDeferred == true, link.matchMethod == "install_referrer", link.confidence == 1.0
navigate(link.path, link.params)
}
When there's no Play referrer, it falls back to signal matching inside the link's attribution window and reports a lower confidence, so you can decide what to trust. iOS and React Native use the same callback. Set-up is in the Android SDK docs, and you can create a free account to try it: the Free plan includes 100 app links.
Checked on 15 November 2026 against Google's Play Install Referrer Library documentation (library 2.2), the com.codeonair:deeplink-android SDK source and the CodeOnAir link server's redirect and matching code.