Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Is it possible to get install referrer programmatically

I have noticed some Google Play app links in the browser has the referrer= attribute to them, which obviously tells the referrer that sent you to that app's page in Google Play.

Is it possible to see that referrer (if any) in the code of my app? And if not, to see it anywhere at all?

like image 367
Borislav Avatar asked May 07 '15 13:05

Borislav


People also ask

How do I do a test install referrer?

If all goes well, you should be able click the generated URL on your Android device, go to the Play store, install the "Referrer Test for Google Play" application, run the application, and see the referrer string you entered on this site show up in the log within the application.

What is install referrer API?

The Play Install Referrer API is an AIDL Service Interface primarily used by non-Java programmers. Note: The Play Install Referrer Library provides a wrapper around the Play Install Referrer API and is designed to help Java programmers use the API.

Is Play install referrer API permission safe?

You can use the Google Play Store's Install Referrer API to securely retrieve referral content from Google Play, such as: The referrer URL of the installed package. The timestamp, in seconds, of when a referrer click happened (both client- and server-side).

How does Google Play install referrer work?

The Play Install Referrer API Client Library is written in the Java programming language and is a wrapper for the Android Interface Definition Language (AIDL) file that defines the interface to the Install Referrer service. You can use the Play Install Referrer API Client Library to simplify your development process.


3 Answers

You can use com.android.vending.INSTALL_REFERRER.

The Google Play com.android.vending.INSTALL_REFERRER Intent is broadcast when an app is installed from the Google Play Store.

Add this receiver to AndroidManifest.xml

<receiver
    android:name="com.example.android.InstallReferrerReceiver"
    android:exported="true"
    android:permission="android.permission.INSTALL_PACKAGES">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

Create a BroadcastReceiver:

public class InstallReferrerReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String referrer = intent.getStringExtra("referrer");

        //Use the referrer
    }
}

You can test the referral tracking following the steps of this answer.

like image 104
Mattia Maestrini Avatar answered Oct 08 '22 02:10

Mattia Maestrini


Use Google Play Referrer API (from 20 Nov 2017)

InstallReferrerClient mReferrerClient
...
mReferrerClient = newBuilder(this).build();
mReferrerClient.startConnection(this);

@Override
public void onInstallReferrerSetupFinished(int responseCode) {
   switch (responseCode) {
       case InstallReferrerResponse.OK:
           try {
               ReferrerDetails response = mReferrerClient.getInstallReferrer();
               String referrer = response.getInstallReferrer()
               mReferrerClient.endConnection();
           } catch (RemoteException e) {
               e.printStackTrace();
           }
           break;
       case InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
           Log.w(TAG, "InstallReferrer not supported");
           break;
       case InstallReferrerResponse.SERVICE_UNAVAILABLE:
           Log.w(TAG, "Unable to connect to the service");
           break;
       default:
           Log.w(TAG, "responseCode not found.");
   }
}
like image 21
Deven Avatar answered Oct 08 '22 00:10

Deven


Campaign Parameters are used to pass information about the campaign or traffic source that referred a user to your app's Google Play Store page into your app's Google Analytics implementation.

Once you've built your campaign parameter string, add it to your Google Play Store URLs as the value of the referrer parameter, as in this example:

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

The Google Play Store will pass the value of the referrer parameter to your app's Google Analytics implementation.

References: https://developers.google.com/analytics/devguides/collection/android/v2/campaigns https://developers.google.com/analytics/devguides/collection/android/v2/campaigns#google-play-url-builder

like image 4
aygul Avatar answered Oct 08 '22 01:10

aygul