This is part four of a four-part technical guide on deep linking on Android. The previous posts covered URI schemes, Chrome Intents, and App Links.
Using Google Play Referrer for Deep Linking
One deep linking technique is for a niche use case where the app is not installed. As the developer, you have the option to pass in a custom parameter through the Google Play store that is then received in your app after the user opens it for the first time. This technique allows you to know where this new user came from if you manage this parameter appropriately, and you can create custom landing pages or deep link through the install process. To learn more, keep reading or request a Branch demo.
Requirements for Android Install Referrer
- App must not be installed
- Cannot be used with Chrome intents since you need to structure the Play Store URL
Configuring the Android Install Referrer
In order to configure your app to receive the Android install referrer, you must register your application to receive the
com.android.vending.INSTALL_REFERRER broadcast. Insert the following in between the <application /> tags in your manifest.
In this case,
io.branch.testbed.InstallListener is the name of your custom class that will receive the broadcasts. This is a simple subclass of BroadcastReceiver. Here’s the boilerplate code that you’ll need for this class:
Handling in the App
Once you’ve configured your BroadcastReceiver as described above, handling the intent is easy! It’s a very similar mechanism to handling the URI scheme intents, but it happens from within the onReceive call. You can see an example here:
Practical use for Google Play Referrer
In order to properly use this technique, you must be able to control the link to the Google Play Store that the user interacts with. Let’s say our app package name is
io.branch.testbed, then we know that Google Play can be opened with either of the following:
To append a referrer, you’ll simply need to append
&referrer=specialparam to either of those links. To do this, you’ll need to control the link itself. Note: As you may have noticed reading through the Chrome intent section, you have no control over the Play Store link, meaning that you will not be able to leverage this method.
In order to control the referrer parameter, we’d recommend that you embed it within the client side JS described in the URI method. Here’s a snippet of code that shows how the referrer is added to the market link fallback function that is executed after trying to open the app:
If your eyes are glazing over while reading this, we get it. Google deep linking is incredibly complicated and there are edge cases everywhere. If you use Branch’s tool, you can be confident that your links will just work everywhere.