How to get Google Play referer in an Android application
Asked Answered
W

2

9

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.

Water answered 10/5, 2017 at 14:42 Comment(0)
G
11

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.

Goble answered 11/5, 2017 at 12:18 Comment(2)
Thanks for the answer. But CampaignTrackingService is deprecated (developers.google.com/android/reference/com/google/android/gms/…). You should use only <!-- 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>Stromberg
@AlexMisiulia Thanks for notifying me. I'll update my answer when I get the time to look into the new one -- or if you have a sample, feel free to update it yourself. Cheers!Goble
L
2

Try a Play Install Referrer Library.

It is a new, easy to use and reliable way to securely retrieve install referral content

https://android-developers.googleblog.com/2017/11/google-play-referrer-api-track-and.html

Also, switching to a new referrer API allows for deeper insights into the user conversion funnel, secures the Google Play Store referrer and finally (and most importantly), the additional data provided allows for the complete eradication of click injections.

(source: https://www.adjust.com/blog/eliminating-click-injections-with-google-play-referrer-api/)

Example:

final InstallReferrerClient referrerClient = InstallReferrerClient.newBuilder(YourActivity.this).build();
referrerClient.startConnection(new InstallReferrerStateListener() {

        @Override
        public void onInstallReferrerSetupFinished(int responseCode) {
            switch (responseCode) {
                case InstallReferrerClient.InstallReferrerResponse.OK:

                    try {
                        ReferrerDetails response = referrerClient.getInstallReferrer();
                        String installReferrer = response.getInstallReferrer();

                        // handle referrer string

                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                    break;

                case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                    // API not available on the current Play Store app
                    break;
                case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                    // Connection could not be established
                    break;
            }
        }

        @Override
        public void onInstallReferrerServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }
});

Add the following line to the dependencies section of the build.gradle file for your app:

dependencies {
    ...
    compile 'com.android.installreferrer:installreferrer:1.0'
}
Linguiform answered 27/8, 2018 at 14:25 Comment(1)
Can you explain how to test this while developing?Bulahbulawayo

© 2022 - 2024 — McMap. All rights reserved.