Android Uninstall Tracking

AppsFlyer's Uninstall Tracking feature allows you to track the number of uninstalls that have occurred for a particular app and then attribute them back to a specific media source. With this metric, you can optimize your advertising budget and strategy with those media sources providing the highest value users.

Prerequisites:

  • An Android application with AppsFlyer SDK Integrated.
  • GCM/Firebase Project's Server Key (as described below).

NOTES:  

  • Tracking uninstalls using Firebase Messaging is supported from Android SDK version 4.7.0.  For previous SDK versions, use GCM.
  • If you are using multiple InstanceIDListener services, you can create your own Listener and transfer the token to AppsFlyer's API, as shown below.

How to Enable AppsFlyer's Uninstall Tracking

Does your Android app have Google Cloud messaging or FireBase integrated or not?

Add the following code to your app and then follow the instructions below according to your GCM/FireBase integration status.

In your MainActivity's onCreate method, provide the AppsFlyer SDK with the your project's SenderID (AKA - Project Number), as the following example:

@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
String senderId = "Your-Sender-ID"; // A.K.A Project Number;
AppsFlyerLib.getInstance().enableUninstallTracking(senderId); // ADD THIS LINE HERE
// ...
AppsFlyerLib.getInstance().startTracking(getApplication(), "YOUR_DEV_KEY");
// ...
}

Application Without GCM/Firebase Messaging

If your app does NOT use a Google's Push Notification service (GCM or Firebase), then follow these instructions:

  • Obtain your Firebase project's Server Key (If you haven't already, create a new Firebase project, and follow the Firebase's instructions).  (See below for instructions how to do this).
  • Enter the Server Key to your AppsFlyer dashboard (see below for instructions how to do this).
  • Configure Firebase Messaging on your app  (see below for instructions how to do this).
  • Add the following code to your application as described:
    • Add the Firebase Dependency to your app's build.gradle file, as the following:
dependencies {
// ...
compile 'com.google.firebase:firebase-messaging:10.0.1'
// ...
}
    • Add these lines to your app's AndroidManifest.xml file, inside the application tag:
<application
<!-- ... -->  
       <service
           android:name="com.appsflyer.FirebaseInstanceIdListener">
           <intent-filter>
               <action
android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
           </intent-filter>
       </service>
<!-- ... -->
</application>

Application with Firebase Messaging Integrated

If you have Firebase Notifications integrated into your application, then follow these instructions:

  • Obtain your Firebase project's Server Key (see below for instructions how to do this).
  • Enter the Server Key to your AppsFlyer dashboard (see below for instructions how to do this).
  • Add the following code to your application as described:
    • In your InstanceIDListener Service's onTokenRefresh method (a class extending com.google.firebase.iid.FirebaseInstanceIdService), call our API inside the overrided method onTokenRefresh, as in the following example:
import com.appsflyer.AppsFlyerLib;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

public class MyInstanceIdService extends FirebaseInstanceIdService {

@Override
public void onTokenRefresh() {
super.onTokenRefresh();

// Get updated InstanceID token.
FirebaseInstanceId instance = FirebaseInstanceId.getInstance();
String refreshedToken;
if (instance != null) {
refreshedToken = instance.getToken();
// ...
sendTokenToMyBackend(refreshedToken); // example for general use case
// ...
AppsFlyerLib.getInstance().updateServerUninstallToken(getApplicationContext(), refreshedToken); // ADD THIS LINE HERE
}
}
}

Application with Google Cloud Messaging (GCM) Integrated

If you have GCM integrated on your Application, then follow these instructions:

  • Obtain your GCM project's Server Key (see below for instructions how to do this).
  • Enter the Server Key to your AppsFlyer dashboard (see below for instructions how to do this).
  • In your InstanceIDListener Service's onTokenRefresh method (a class extending com.google.android.gms.iid.InstanceIDListenerService), call our API inside the overridden method onTokenRefresh, as in this following example:
import android.util.Log;
import com.appsflyer.AppsFlyerLib;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;
import com.google.android.gms.iid.InstanceIDListenerService;

public class MyInstanceIdService extends InstanceIDListenerService {

@Override
public void onTokenRefresh() {
super.onTokenRefresh();

// Get updated InstanceID token.
String senderId = "Your-Sender-ID"; // A.K.A Project Number;
InstanceID instance = InstanceID.getInstance(getApplicationContext());
try {
String refreshedToken = instance.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
if (refreshedToken != null) {
AppsFlyerLib.getInstance().updateServerUninstallToken(getApplicationContext(), refreshedToken); // ADD THIS LINE HERE
}
} catch (Throwable e) {
Log.e("MyInstanceIdService", "onTokenRefresh: Couldn't get the refreshed token.", e);
}
}
}

Obtaining the Firebase/GCM Server Key

1.  Create a Firebase Android Application project (if you have not already done so), or migrate your project from Google Developer Console (follow the instructions there). For more information, visit this link:

https://firebase.google.com/docs/notifications/android/console-audience#add_firebase_to_your_app.

2.  Open the Firebase Console: https://console.firebase.google.com.

3.  In the Firebase Console page, navigate to the Project Settings (click on the cogwheel next to Overview on the left pane of the page).

4.  Under the Cloud Messaging tab, you can see your Sender ID (A.K.A Project Number, which is essential if you are using GCM) and two Server Keys (see screenshot below):

  • Server Key - used with Firebase-Messaging
  • Legacy Server key - used with GCM

https://support.appsflyer.com/hc/en-us/article_attachments/207033103/firebase.png

5.  Copy the Server Key.

  • You can also use the deprecated Google Developer Console to get these values -

https://console.developers.google.com/apis/credentials.

Entering the Server Key on AppsFlyer Dashboard

1.  Go to your app's dashboard on the AppsFlyer platform.

2.  Select App Settings from the left menu.

3.  Set the Firebase Server Key with the Server Key you just copied (this is a unified Server Key field for both GCM & Firebase-Messaging).

Configuring Firebase-Messaging on your App

Once you have created the project on Firebase Console, you should have also downloaded your project's JSON file: google-services.json, and saved it under your application's module directory.

  • If you do not have this file, you can download it from your Project Settings in the Firebase Console.

Then, you must add the Firebase-Messaging dependencies to your project. To do this, first add rules to your root-level build.gradle file, to include the google-services plugin:

buildscript {
   // ...
   dependencies {
       // ...
       classpath 'com.google.gms:google-services:3.0.0' // ADD THIS LINE HERE
   }
}

Then, in your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin, and add the dependency inside the dependencies block:

apply plugin: 'com.android.application'

android {
 // ...
}

dependencies {
 // ...
 compile 'com.google.firebase:firebase-messaging:10.0.1' // ADD THIS LINE AT THE BOTTOM OF THIS BLOCK
}

apply plugin: 'com.google.gms.google-services' // ADD THIS LINE AT THE BOTTOM OF THIS FILE

If you are receiving a "Could not find.." error, make sure you have the latest Google Repository in the Android SDK Manager.

Using ProGuard with Uninstall Tracking

When using ProGuard it is required to add the following rules according to which Messaging Service is used (Firebase or GCM).

When using Firebase add the following rules: 

-dontwarn com.appsflyer.**
-keep public class com.google.firebase.iid.FirebaseInstanceId {
   public *;
}

When using GCM add the following rules:

-dontwarn com.appsflyer.**
-keep public class com.google.android.gms.iid.InstanceID {
   public *;
}

Testing Android Uninstall Tracking

Testing the implementation of android's uninstall tracking is very straight forward.

Whether the android app is live on Google Play, pending submission or even out of store, the test is the same - simply uninstalling the app from the device.

Allow up to 24 hours for the new app uninstall event to be displayed on the dashboard's aggregated performance report table and on the uninstalls raw data report.

 

Was this article helpful?
0 out of 2 found this helpful
Have more questions? Submit a request
Powered by Zendesk