Uninstall Tracking using Appsflyer in Android

Posted By : Prince Bhardwaj | 29-Jun-2017

Appsflyer uninstall tracking allows you to track the number of unistalls that have occured for a particular application and then attribute them back to specific media source.

 

Prerequisites -

 

1. An android application with appsflyer integrated.

2. GCM/Firebase server key.

 

How to enable Appsflyer's Uninstall Tracking -

 

To enable Appsflyer's Uninstall Tracking feature, you have to follow these steps -

 

Application without GCM/Firebase integrated -

 

   1. Obtain your Firebase project's server key. If you don't have, create a new Firebase Project and follow firebase instructions.

   2. Enter the server key to your Appsflyer dashboard.

   3. Configure Firebase Messaging to your app.

   4. Add the following code to your application.

        Add the Firebase dependency to your app's build.gradle file -

dependencies {
 // ...
    compile 'com.google.firebase:firebase-messaging:10.0.1'
 // ...
}
 
 

 Add these line to your manifest file - 

 

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

 

   1. Obtain your Firebase project's server key.

   2. Enter the server key to your Appsflyer dashboard.

   3. Add the following code to your applictaion - 

       

 In your InstanceIdListener service onTokenRefresh method, add these lines -

 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 GCM(Google Cloud Messaging) Integrated -

 

   1. Obtain your Firebase project's server key.

   2. Enter the server key to your Appsflyer dashboard.

   3. Add the following code to your applictaion - 

      Add these lines to your MainActivity onCreate method -

 @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");
 // ...
}
 

 

  In your InstanceIdListener service onTokenRefresh method, add these lines -

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

 

 

 

 

About Author

Author Image
Prince Bhardwaj

Prince Bhardwaj is having Talent as Application Developer, he is an enthusiastic team player in Oodles Technologies.

Request for Proposal

Name is required

Comment is required

Sending message..