Analysing App Installs

Joris Verbogt
Joris Verbogt
Dec 4 2020
Posted in Engineering & Technology

Track the source of your users in Android

Analysing App Installs

Imagine you set up a compelling campaign that convinced your users to install your app on their devices. Wouldn't it be nice to know if they actually installed your app because of that campaign?

Android (Google Play Store)

If the user installed your app via the Google Play Store, you can use the Google Play InstallReferrer package to gather information around the installation of the app on the device.

Add dependency

dependencies {
    implementation 'com.android.installreferrer:installreferrer:2.1'
}

Implementation

The easiest way to take action on the install is when your app is launched for the first time, although the InstallReferrerClient class can be invoked at all times. If you want to lead the user to a specific screen depending on their origin or even a continuation of a flow they were executing before installing the app, first launch is the place where you would retrieve this information.

For example:

private fun checkInstallReferrer() {
    val referrerClient: InstallReferrerClient = InstallReferrerClient.newBuilder(this).build()
    referrerClient.startConnection(object : InstallReferrerStateListener {
        override fun onInstallReferrerSetupFinished(responseCode: Int) {
            when (responseCode) {
                InstallReferrerClient.InstallReferrerResponse.OK -> {
                    // Connection established.
                    var response: ReferrerDetails? = null
                    try {
                        response = referrerClient.installReferrer
    
                        // At this point, you have all the info around the install

                        // response.installReferrer is the value that was passed as referrer
                        Log.i(TAG, "our app was installed via ", response.installReferrer)

                    } catch (e: RemoteException) {
                        Log.w(TAG, "error getting install referrer: " + e.message)
                        referrerClient.endConnection()
                    } catch (e: JSONException) {
                        Log.w(TAG, "error logging install referrer: " + e.message)
                        referrerClient.endConnection()
                    }
                }
                InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
                    Log.w(TAG, "error getting install referrer: feature not supported")
                }
                InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
                    Log.w(TAG, "error getting install referrer: service unavailable")
                }
            }
        }

        override fun onInstallReferrerServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }
    })
}

Now call this method at first launch of your app. The content of response.installReferrer is the literal string that was passed to the install link as the referrer= query parameter

Huawei Mobile Services

If your app is distributed through the Huawei AppGallery, there is a similar package that contains the necessary classes to determine the install referrer. The class that handles this is also called InstallReferrerClient and has the same interface as the Google one, so if your app is built for both platforms, you should make sure you only use one of these two classes during launch.

Add dependency

dependencies {
    implementation 'com.huawei.hms:ads-installreferrer:3.4.34.301'
}

Implementation

The implementation is basically the same as for Google Play (see above), but in this case you should not to call startConnection on the main thread.

val installReferrerThread = Thread { checkInstallReferrer() }

installReferrerThread.start()

Now what?

Now that you know the source of your install, you can do several things:

  • Log the install with the referrer to your analytics API
  • Open a welcome screen that is related to the source
  • Parse the referrer as a deeplink

The latter action is especially useful when you want to offer the user an opportunity to finish a flow after installing the app. This can be achieved by using Dynamic Links in your campaigns so users that have the app installed continue the flow inside the app and users that do not have the app yet are redirected to the store to install the app.

Notificare Dynamic Links

When your app was installed via a Dynamic Link in Notificare, the actual link that was used is passed along inside the referrer as ntc_link.

So for example if you defined a dynamic link https://myamazingapp.ntc.re/XkEVXciA4ZG that is set up to direct the user to Google Play if the app is not found on the device, your install referrer client will receive ntc_link=https://myamazingapp.ntc.re/XkEVXciA4ZG as the referrer.

Your app can then use the value of ntc_link to open the target deeplink that your app would have received if the dynamic link was clicked with the app installed.

Notificare.shared().fetchDynamicLink(Uri.parse(ntcLink), object : NotificareCallback<NotificareDynamicLink> {
    override fun onSuccess(notificareDynamicLink: NotificareDynamicLink) {
        val intent = Intent()
        intent.action = "android.intent.action.VIEW"
        intent.data = Uri.parse(notificareDynamicLink.target)
        startActivity(intent)
    }

    override fun onError(notificareError: NotificareError) {}
})

Conclusion

The combination of dynamic links and install referrer tracking allows for a tailor-made onboarding experience of your users while giving you the insights you need to determine the conversion of your campaigns.

If you are interested in trying Notificare Dynamic Links in combination with the code samples above, please follow our step-by-step documentation.

As always, we remain available for any suggestions, corrections or questions you might have, via our Support Channel.

Keep up-to-date with the latest news