Android Uninstall Tracking

Introduction

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.

To start using uninstall tracking for Android mobile apps you MUST have GCM or Firebase Project's Server Key (as described below).

 Important

Firebase Cloud Messaging (FCM) is the new version of GCM: It inherits the reliable and scalable GCM infrastructure, plus new features. If you are integrating messaging in a new app, start with FCM. GCM users are strongly recommended to upgrade to FCM, in order to benefit from new FCM features today and in the future.

 

 Tip

Tracking uninstalls using Firebase Messaging is supported from Android SDK version 4.7.0.

If your app has a previous Android SDK version, use GCM, or upgrade to the latest Android SDK version and use FCM.

Step 1: 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

5.  Copy the Server Key.

Step 2: 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.

Android_Uninstall_new.png


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).

Step 3: 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:

Firebase GCM
  1. Add rules to your root-level build.gradle file, to include the google-services plugin:
buildscript {  
       // ...  
       dependencies {  
           // ...  
           classpath 'com.google.gms:google-services:3.1.0' // google-services plugin  
       }  
   }
  1. Add the FCM dependency to your app-level build.gradle file:
dependencies {
    compile 'com.google.firebase:firebase-messaging:11.4.0'
}

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

Note - the latest Firebase version can be found here: Firebase official doc.

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

3. Copy the google-services.json file that was downloaded from the Firebase Console to the applications app directory.

Step 4: Setting Sender ID

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");

/* ... */
}

Step 5: Implementing AppsFlyer Uninstall Tracking Service  

Firebase GCM
Developers who first use Firebase for AppsFlyer uninstall tracking

If a developer integrates FCM for the sole purpose of tracking uninstalls with AppsFlyer, he can make use of the appsFlyer.FirebaseInstanceIdListener service, included in our SDK.

This is done by adding the service to the AndroidManifest.xml:

<application  
    <!-- ... -->    
           <service  
               android:name="com.appsflyer.FirebaseInstanceIdListener">  
               <intent-filter>  
                   <action  
     android:name="com.google.firebase.INSTANCE_ID_EVENT"/>  
               </intent-filter>  
           </service>  
    <!-- ... -->  
</application>

The appsflyer.FirebaseInstanceIdListener extends Firebase's <>FirebaseInstanceIdService class, which is used in order to receive Firebase's Device Token.

Developers who already use Firebase for other third party platforms
If a developer intends to use FCM with more than one platform / SDK, he would need to implement a logic that collects the Device Token and passes it to all relevant platforms. This is done by extending a new instance of the FirebaseInstanceIdService (similar to the service the AppsFlyer SDK extends) :
import com.appsflyer.AppsFlyerLib;  
import com.google.firebase.iid.FirebaseInstanceId;  
import com.google.firebase.iid.FirebaseInstanceIdService;  
      
    public class MyNewInstanceIdService 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 / 3rd party SDK */
          /* pass the token to the AppsFlyer SDK */
          AppsFlyerLib.getInstance().updateServerUninstallToken(getApplicationContext(), refreshedToken); 
	}  
    }  
}
That service should be added to AndroidManifest.xml in order to function: If the application was using FCM before integrating the AppsFlyer SDK, most chances are that this service has already been extended and the developer would just need to add the following line to the onTokenRefresh() method:
AppsFlyerLib.getInstance().updateServerUninstallToken(getApplicationContext(), refreshedToken); 

Step 6: 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).

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

Step 7: 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.

 APR.png

 Note

Viewing uninstalls filtered by country only is currently unavailable.

Was this article helpful?
1 out of 4 found this helpful