androidgoogle-play-servicesreferer

How to get Google Play referer in an Android application


We are developping an Android application. And we want to track our compaigns. Basically, we want to know from where our users arrives to Google play, by putting a word in the Google Play URL with our parteners and retrieve that word in the application and then send it to our server.

We have already installed Google Analytics to our application, we are able to track what the user does in the application on the Google statistics board. But how can we use it to achieve what we really want ? We really need to link our users data base with that word.

I heard about INSTALL_REFERER, but I really don't know how to use it.


Solution

  • You are looking for Campaign Measurement. In the documentation, it discusses how using INSTALL_REFERRER will help you determine which source is sending users to your App in the Google Play Store.

    It's as simple as placing a receiver in your AndroidManifest and modifying your App's Google Play URLs.

    From the docs:

    Google Play Campaign Attribution

    Google Play Campaign Measurement allows you to see which campaigns and traffic sources are sending users to download your app from the Google Play Store. It is recommended that all developers implement Google Play Store Campaign Measurement.

    Implementing Google Play Campaign Attribution

    When your app is downloaded from Google Play Store, the Play Store app broadcasts an INSTALL_REFERRER intent to your app during installation. This intent contains the value of the referrer parameter of the link used to reach your app's Google Play Store page, if one was present.

    To attribute an app download to a campaign, you must add a referrer parameter to any links that point to Google Play Store, and add a BroadcastReceiver to your app to receive and set the campaign information contained in the intent on your Google Analytics tracker.

    It is recommended that most developers use the BroadcastReceiver provided with the SDK. To implement Google Play Store Campaign Measurement using the included receiver:

    1. Add the Google Analytics receiver to your AndroidManifest.xml file. To add the Google Analytics receiver to the manifest, copy and paste the following markup:

        <application>
        <!-- Used for Google Play Store Campaign Measurement-->
        <receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>
        <service android:name="com.google.android.gms.analytics.CampaignTrackingService"
            android:enabled="true"
            android:exported="false" />
    </application>
    
    1. Add Google Analytics Campaign Parameters to Google Play URLs

      Next, add a referrer parameter to any URLs that will be linking directly to Google Play Store and set the value of that parameter to a string of Google Analytics campaign parameters that describe the source, as in this example:

      https://play.google.com/store/apps/details?id=com.example.application &referrer=utm_source%3Dgoogle %26utm_medium%3Dcpc %26utm_term%3Drunning%252Bshoes %26utm_content%3Dlogolink %26utm_campaign%3Dspring_sale

    To learn how to build a campaign parameter strings, use the Google Play URL Builder, or consult the Campaign Parameters reference section.

    Testing Google Play Campaign Attribution

    To verify that your Google Play Campaign Measurement implementation is working as expected before publishing your app, use the Testing Google Play Campaign Attribution Solution Guide.

    Also, see this similar post.