Install Referrer for Android using Google Play Campaign Measurement

After developing and publishing any Android app we go for analytics to see different statistics like installation & uninstallation, usage, user behaviour, cohort analysis, install referrer etc. using Google Analytics. Popular apps use to advertise or run digital campaign in order to grow installation rate. When a user installs a your app from play store via some campaign/advertisement you may want to see how they came to your app and which campaign worked for you. In this article we will discuss how to detect a new user coming to your app via campaign you ran and test it. We will achieve this using Google Play Campaign Attribution. It helps you to see which website or app or advertising tool referred other user to download your app.

SET UP INSTALL REFERRER

Before we move, we need to add Google services JSON (google-services.json) file in app folder in order to access Google services in you app. See this for referrence.

Now, to set up install referrer first you need to add Google Services to your android app. Go to your build.gradle(Project level) and add

As you can see we have added CampaignTrackingReceiver with INSTALL_REFERRER intent. Play Store app sends data to this intent and here we are adding our receiver UtmReceiver that extends CampaignTrackingReceiver. Now take a look at the UtmReceiver class.

As you can find UtmReceiver extends CampaignTrackingReceiver to receive campaign data and find install referrer. We get the data via bundle extras with the key “referrer”. The inner block describes how to get values based on keys explained in the section below. After getting the values we save it to SharedPreferences to get the values letter in our app.

UNDERSTANDING THE PARAMETERS

We have already got the values against different keys from campaign data. Now we need to understand what are the keys and their purposes.
These keys comes with the Google Play Campaign URL. To see the url format you can check this Google Link and build your own url for campaign tracking.

Now look at the keys for which we get the values mentioned in the above image.

CAMPAIGN PARAMETERS

1

2

3

4

5

6

7

8

9

utm_source-Campaign Source

utm_medium-Campaign Medium

utm_term-Campaign Term

utm_content-Campaign Content

utm_campaign-Campaign Name

Next we will display the value we received via INSTALL REFERRER. So our MainActivity would look like

In the above code we fetched the values from SharedPreferences and displayed in a TextView.
Our programming part ends here. In the next section we will see how we test it.

TESTING INSTALL REFERRER CAMPAIGN

So far we have seen how to get campaign tracking attributes and decode them. Now it’s time to test the code running as expected. We may think How to test it without publishing app to Play Store?. Don’t worry! There is alternative way.

To test install referrer first we need to go to adb folder from terminal in Android Studio or the terminal your os provides. The path looks like ~/Android/Sdk/platform-tools/adb

To broadcast INSTALL_REFERRER intent make sure your app is installed but not running, not even in background.

The above command consists of values like utm_source, utm_medium etc. as given in Google Play URL builder in above section of this article. If the broadcast is successful you will get following message in return on the terminal

Abhishek is a developer cum blogger working more than 4 years. He loves programming especially open stack technologies. He has decent knowledge in Android development, Wordpress, MongoDB, Node.js and so on. Beside this Abhishek finds himself busy in painting, front-end designing.

Follow Abhishek

Previous

Android : Detect new Contact addition

Next

Featured Post

ExoPlayer is an Android Application level Media Player by Google. It is used for playing media(both audio and video) from local or remote. In this article we will discuss how to play or stream remo ... Read More