# Understanding Referrals using Google Play

DevFeed: [Understanding Referrals using Google Play](<https://devfeed.tech/articles/understanding-referrals-using-google-play-25114.md>)

Original publisher: [Read original article](<http://michaelevans.org/blog/2024/06/27/understanding-referrals-using-google-play/>)

Author: Michael Evans

Published: 2024-06-27T23:41:33Z

Content type: tutorial

Language: en

Sources: [Gadget Habit](<https://devfeed.tech/sources/gadget-habit.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [API](<https://devfeed.tech/topics/api.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Google](<https://devfeed.tech/topics/google.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Library](<https://devfeed.tech/topics/library.md>), [App](<https://devfeed.tech/topics/app.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [app](<https://devfeed.tech/tags/app.md>), [build](<https://devfeed.tech/tags/build.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [data](<https://devfeed.tech/tags/data.md>), [dependency](<https://devfeed.tech/tags/dependency.md>), [google](<https://devfeed.tech/tags/google.md>), [google-play](<https://devfeed.tech/tags/google-play.md>), [guide](<https://devfeed.tech/tags/guide.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [installreferrerclient](<https://devfeed.tech/tags/installreferrerclient.md>), [integration](<https://devfeed.tech/tags/integration.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [marketing](<https://devfeed.tech/tags/marketing.md>), [play-store](<https://devfeed.tech/tags/play-store.md>), [prevent-fraud](<https://devfeed.tech/tags/prevent-fraud.md>)

## AI overview

A tutorial on using the Google Play Install Referrer API in an Android application. It explains how install referrer data supports campaign attribution, marketing measurement, and fraud prevention, then shows how to integrate InstallReferrerClient with Kotlin callbackFlow and collect the resulting flow.

## Source excerpt

Tracking how users install your app can be tricky, especially when you want to measure the effectiveness of your campaigns or ads. That's where the Google Play Install Referrer API comes in handy--it gives you reliable data about how users found your app. If you're developing an Android application, this guide will walk you through how to set up and use the InstallReferrerClient with Kotlin's callbackFlow to make integration simpler and more maintainable. What is the Install Referrer? The install referrer contains information about the source of the app installation. For example, if a user clicks an ad campaign link that leads to your app's Play Store page, the referrer might include details about the campaign source, medium, or other specifics. Here's how this data can help: Attribution: Identify which campaigns drive installs. Measure Success: Evaluate your marketing efforts' impact. Prevent Fraud: Verify referrer data to avoid fraudulent installs. Setting Up and Using the InstallReferrerClient Step 1: Add the Dependency First, include the Install Referrer library in your build.gradle file: 1 implementation 'com.android.installreferrer:installreferrer:2.2' Step 2: Use callbackFlow for our implementation The InstallReferrerClient is callback-based, but Kotlin's callbackFlow lets you handle this more elegantly. Here's an example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 import com.android.installreferrer.api.InstallReferrerClient import com.android.installreferrer.api.InstallReferrerStateListener import com.android.installreferrer.api.ReferrerDetails import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.callbackFlow fun fetchInstallReferrer(context: Context) = callbackFlow { val referrerClient = InstallReferrerClient.newBuilder(context).build() val listener = object : InstallReferrerStateListener { override fun onInstallReferrerSetupFinished(responseCode: Int) { when (r