[WIP]Integrate Android uninstall measurement into an app

At a glance: Setup uninstall measurement in Android apps by integrating Firebase Cloud Messaging into the app.

Related reading: Principles of uninstall measurement

Android uninstall measurement

Android uninstall measurement is available by configuring uninstall measurement in AppsFlyer and adopting Firebase Cloud Messaging (FCM) into your app. Starting April 2021, AppsFlyer supports both the FCM legacy API and HTTP V1 API. FCM encourages the adoption of the V1 version

 

Uninstall measurement implementation checklist 
Step Action Responsibility
1 Connect FCM to AppsFlyer

Select an integration API:

Marketer/developer
2

Integrate FCM into the app

The integration differs if you use FCM only with AppsFlyer or you use it with multiple platforms.

  1. Adopt FCM into the app.
  2. Do one of the following:
  3. [Optional] If you use Proguard, complete Enabling Proguard.
Developer
3 Test uninstall measurement Developer

 

Connect FCM API to AppsFlyer

Select an FCM API version [Best practice] HTTP V1 or legacy HTTP. 

HTTP V1

To configure FCM API V1 for uninstalls: 

  1. To get the Project ID:
    1. Go to the FCM console.
    2. Select a project. 
    3. Go to Project Overview > Project settings.

      UninstallFirebase.png

    4. Copy the Project ID. You will need it at a later stage in the process. 
  2. To assign AppsFlyer the uninstall role:
    1. Go to the Service accounts tab. 
    2. Click Manage service account permissions
      A new browser tab opens in Google Cloud Platform.
    3. In the side menu, select Roles
    4. Click +Create role.
    5. Complete as follows:
      • Title: Enter AppsFlyer uninstalls.
      • ID: Enter af_uninstalls
      • Role launch stage: Select General availability
    6. Search and then select cloudmessaging.messages.create.

      AddPermissions.png

    7. Click Add.
    8. Click Create
  3. To assign AppsFlyer the FCM uninstall role:
    1. In the side menu, select IAM.
    2. Click + Add.
    3. In the New members field insert af-uninstalls-tracking@af-uninstalls-tracking.iam.gserviceaccount.com
    4. Select a role, select AppsFlyer uninstalls.
    5. Click Save
      The AppsFlyer service account has been assigned the role of AppsFlyer uninstalls. 
  4. To enable uninstall measurement in AppsFlyer:
    1. In AppsFlyer, go to Configuration > App Settings.
    2. If necessary, turn on Uninstall measurement
    3. Select HTTP V1.

      UninstallHTTPV1.png

    4. Enter the Project ID you prepared earlier in this section.
    5. Click Test connection.
      The Success! message displays. 
    6. Click Save settings

Legacy HTTP

Uninstall measurement using Firebase Messaging is supported by Android SDK V4.7.0+

  1. To obtain the Firebase 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, go to Firebase
    2. Open the Firebase Console.
    3. In the Firebase Console, navigate to the Project Settings (click on the cogwheel next to Project Overview on the left pane of the page).

      firebase_cloud_messaging_server_key.png

    4. In the Cloud Messaging tab, you see two Server Keys.
    5. Copy the Server Key.
  2. To enable uninstall measurement in AppsFlyer:
    1. In AppsFlyer, go to Configuration > App Settings.
    2. If necessary, turn on Uninstall measurement
    3. Select Legacy HTTP.
      UninstallLegacy.png
    4. Enter the Firebase/GCM Server Key you prepared in the previous step.
    5. Click Save settings

Integrate FCM into the app

Use the following procedures (as needed) to integrate FCM into the app and test the integration.

Adopt FCM into the app

  • 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.
To adopt FCM in your app:
  1. Download google-services.json from Firebase console.
  2. Add the google-services.json to the app module directory,
  3. Add rules to your root-level build.gradle file, to include the google-services plugin:
    buildscript { 
        // ... 
        dependencies { 
          // ... 
          classpath 'com.google.gms:google-services:4.2.0' // google-services plugin 
        } 
      }
    
  4. Add the FCM dependency to your app-level build.gradle file:

    dependencies {
       implementation 'com.google.firebase:firebase-messaging:17.3.4'
    }
    
    // ADD THIS AT THE BOTTOM 
    apply plugin: 'com.google.gms.google-services
    

Use FCM with the AppsFlyer SDK only

If the sole purpose of integrating FCM is to measure uninstalls in AppsFlyer, use  appsFlyer.FirebaseMessagingServiceListener service, embedded in the SDK. This extends the FirebaseFirebaseMessagingService class, used to receive the FCM Device Token.

To add appsFlyer.FirebaseMessagingServiceListener service to the app:

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

Use FCM with multiple platforms

If you intend to use FCM with more than one platform, SDK, or both, you must implement logic that collects the Device Token and passes it to all relevant platforms. To do by extending a new instance of the FirebaseMessagingService (similar to the service the AppsFlyer SDK extends):
import com.appsflyer.AppsFlyerLib;
import com.google.firebase.messaging.FirebaseMessagingService;

public class MyNewFirebaseManager extends FirebaseMessagingService {

    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);

        // Sending new token to AppsFlyer
       	       AppsFlyerLib.getInstance().updateServerUninstallToken(getApplicationContext(), s);

        // the rest of the code that makes use of the token goes in this method as well
    }
}
That service should be added to AndroidManifest.xml in order to function: If the application used FCM before integrating the AppsFlyer SDK, it is likely that the service is extended and the developer needs to add the following to the onNewToken() method:
AppsFlyerLib.getInstance().updateServerUninstallToken(getApplicationContext(), refreshedToken); 

Verify that have added the relevant service to the AndroidManifest.xml.

<service
    android:name=".MyNewFirebaseManager">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Using Proguard with uninstall measurement

If you use Proguard, add the following rule:

-dontwarn com.appsflyer.**
-keep public class com.google.firebase.messaging.FirebaseMessagingService {
  public *;
}

Test Android uninstall measurement

  • The testing procedure described is valid for apps available via Google Play Store, pending, direct download, and via alternative app stores. 
  • The Uninstalls metric is available in the Overview dashboard.
  • The list of users who uninstall the app is available in the uninstalls raw-data report.

To test Android uninstall measurement:

  1. Install the app.
  2. Uninstall the app.  Note! You can uninstall the app immediately after installing it.
    The uninstall event registers within 24 hours as uninstall measurement is processed daily.
    If the app is reinstalled during this time -
    no uninstall event is recorded.

The app uninstall event takes up to 48 hours to display in raw-data reports and in the Aggregated Performance Report in your AppsFlyer dashboard.

aggregated_performance_report_uninstalls_en-us.png.

Other information

Solving Android uninstall push notification not being silent

Overriding FCMs onMessageReceived method and implementing your own logic in it might cause uninstall push notifications to not be silent. This can impact the user experience. To prevent this, verify that the message contains af-uinstall-tracking. See the following example:

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        
        if(remoteMessage.getData().containsKey("af-uinstall-tracking")){
            return;
        } else {
           // handleNotification(remoteMessage);
        }
    }
Was this article helpful?