Skip to main content

Uninstall Tracking through Firebase Cloud Messaging

Firebase Cloud Messaging (FCM) uninstall tracking detects app uninstalls by monitoring FCM delivery receipts. This method is ideal for Cordova/Ionic apps that already use push notifications.

How FCM Uninstall Tracking Works

  • Purpose: Tracks app uninstalls using FCM delivery receipts to assess user engagement and campaign performance
  • Mechanism: Uses FCM to send silent push notifications and monitors delivery receipts for failed deliveries
  • Detection: Uninstall data typically appears in the panel within 24-48 hours
  • Use Case: Measure uninstall rates for campaigns to refine targeting and improve user retention
Alternative Method

For Firebase Analytics-based uninstall tracking, see Through Firebase Analytics.

Prerequisites

Before implementing FCM uninstall tracking, ensure you have:

  • Firebase project with Cloud Messaging enabled
  • Cordova/Ionic app with Capacitor configured
  • Trackier Cordova SDK properly initialized (version 1.0.0+)
  • @capacitor/push-notifications plugin installed (version 6.0.2+)
  • Android platform (FCM uninstall tracking is Android-only)

Implementation

1. Add Dependencies

Add Capacitor Push Notifications plugin to your project:

npm install @capacitor/push-notifications
npx cap sync

Add the dependency to your package.json:

{
"dependencies": {
"@capacitor/push-notifications": "^6.0.2",
"com.trackier.cordova_sdk": "^1.0.0"
}
}
Latest Version

Check the Capacitor Push Notifications documentation for the latest version and setup instructions.

2. Create FCM Service

Cordova/Ionic Implementation

For Cordova/Ionic apps using Capacitor, we use the Capacitor Push Notifications API instead of native Firebase SDK. This service listens for FCM token registration and sends it to Trackier SDK using trackierCordovaPlugin.sendFcmToken(token.value) - this method should only be called when the token is generated or refreshed, similar to Android's onNewToken() method. The token is automatically saved by the Trackier SDK.

Create an Angular service to handle FCM token management:

src/app/services/fcm.service.ts
import { Injectable } from '@angular/core';
import { Platform } from '@ionic/angular';
import { PushNotifications, Token } from '@capacitor/push-notifications';
import { TrackierCordovaPlugin } from '@awesome-cordova-plugins/trackier/ngx';

@Injectable({
providedIn: 'root'
})
export class FcmService {
constructor(
private platform: Platform,
private trackierCordovaPlugin: TrackierCordovaPlugin
) {}

async initializeFCM(): Promise<void> {
try {
if (!this.platform.is('android')) {
console.log('FCM is only initialized on Android platform');
return;
}

const permStatus = await PushNotifications.requestPermissions();

if (permStatus.receive === 'granted') {
await PushNotifications.register();

PushNotifications.addListener('registration', (token: Token) => {
console.log('FCM Token received:', token.value);
this.trackierCordovaPlugin.sendFcmToken(token.value);
});

PushNotifications.addListener('registrationError', (error: any) => {
console.error('Error on FCM registration:', error);
});
}
} catch (error) {
console.error('Error initializing FCM:', error);
}
}
}
Important FCM Token Behavior

FCM tokens are generated only once when the app is first installed or when Firebase generates a new token. If you run the app once and don't see the token in logs, you won't see it again on subsequent runs. To see the token again, you need to:

  1. Uninstall the app completely
  2. Reinstall the app
  3. Check logs immediately for the token

This is normal FCM behavior - tokens are not generated on every app launch, only when:

  • App is first installed
  • Firebase generates a new token (rare)
  • App data is cleared
  • App is restored on a new device

3. Initialize Trackier SDK and FCM

Initialize the Trackier SDK first, then initialize FCM:

src/app/app.component.ts
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { TrackierCordovaPlugin, TrackierConfig } from '@awesome-cordova-plugins/trackier/ngx';
import { FcmService } from './services/fcm.service';

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
})
export class AppComponent {
constructor(
private platform: Platform,
private trackierCordovaPlugin: TrackierCordovaPlugin,
private fcmService: FcmService
) {
this.initializeApp();
}

async initializeApp() {
await this.platform.ready();

const trackierConfig: TrackierConfig = {
appToken: 'YOUR_SDK_KEY',
environment: 'production'
};

await this.trackierCordovaPlugin.initializeSDK(trackierConfig);

// Initialize FCM after SDK initialization
if (this.platform.is('android')) {
await this.fcmService.initializeFCM();
}
}
}
Important - Call After SDK Initialization

Always call initializeFCM() after the Trackier SDK has been initialized. The SDK must be ready before sending the FCM token. Calling it before SDK initialization will result in the token not being properly registered.

4. Verify Firebase Configuration

Ensure your Firebase configuration is properly set up in your Android app:

4.1 Add google-services.json

Place your google-services.json file in the Android app directory:

android/app/google-services.json

4.2 Configure build.gradle (If Not Using Capacitor Plugin)

Automatic Configuration with Capacitor

If you're using @capacitor/push-notifications plugin, the Firebase Messaging dependency and Google Services plugin are typically configured automatically when you run npx cap sync. You may skip this step unless you encounter build issues.

If needed, manually add the Google Services plugin to your android/build.gradle:

buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}

Apply the plugin in android/app/build.gradle:

apply plugin: 'com.google.gms.google-services'

dependencies {
implementation 'com.google.firebase:firebase-messaging'
}

5. Firebase Console Configuration

Step 1: Connect Product to Firebase

If you haven't already connected your product to Firebase:

  1. Go to the Firebase Console
  2. Create a new project or select an existing one
  3. Add your Android app to the project
  4. After setting up the project on console, go to Settings
  5. In the General tab, see the Project ID and copy it

Step 2: Configure in AppTrove Panel

  1. Go to your AppTrove panel
  2. Navigate to Settings page
  3. Go to Uninstall Tracking tab
  4. Paste the Project ID you copied from Firebase Console
  5. Enable the toggle for uninstall tracking

Step 3: Enable Cloud Messaging API

  1. Go to the Cloud Messaging tab
  2. Check if Firebase Cloud Messaging API (V1) is enabled

If not enabled:

  1. Go to Service accounts tab

  1. Go to Library
  2. Search for Firebase Cloud Messaging API
  3. Click Enable

Step 4: Create Custom Role for AppTrove

  1. In the side menu, select Roles
  2. Click +Create role

  1. Complete the form as follows:
    • Title: Enter AppTrove Uninstall
    • ID: Enter at_uninstalls
    • Role launch stage: Select General availability
  2. Click Add permissions

  1. In the Filter field, search for: cloudmessaging.messages.create
  2. Select the permission and click Add
  3. Click Create
Verify Role Creation

After creating the role, check and verify that the AppTrove Uninstall role has been added successfully with the cloudmessaging.messages.create permission.

Step 5: Assign AppTrove the FCM Uninstall Role

  1. In the side menu, select IAM
  2. Click Grant Access

  1. In Add PrincipalsNew principals, enter: at-uninstalls-tracking-tra-430@trackier-mmp.iam.gserviceaccount.com
  2. In Assign rolesRole select Custom and choose AppTrove Uninstall (the role we created earlier)
  3. Click Save
Service Account Email

Use this exact email address: at-uninstalls-tracking-tra-430@trackier-mmp.iam.gserviceaccount.com

Step 6: Verify Permissions

  1. Go to IAM & AdminIAM
  2. Search for the service account you just added
  3. Verify that the AppTrove Uninstall role is assigned

Verification and Testing

1. Test FCM Token Registration

When your app starts, check the logs to verify the FCM token is being sent to Trackier:

npx cap run android

Verify in Android Studio Logcat:

  1. Open your Android project folder in Android Studio
  2. Run the app on a device or emulator
  3. Open Logcat in Android Studio
  4. Set the filter to trackiersdk to see only Trackier-related logs
  5. Check for the following log messages:
Initializing FCM...
FCM Token received: [YOUR_FCM_TOKEN]
FCM Token sent to Trackier SDK successfully

Check Token Response: Look for the log message Fcm token Api response saved successfully

Expected Log Output:

D/trackiersdk: Fcm token Api response saved successfully

2. Test Uninstall Detection

  1. Install your app and register FCM token
  2. Uninstall the app
  3. Wait 24-48 hours for the uninstall data to be processed
  4. Check AppTrove dashboard for uninstall event

3. Monitor AppTrove Dashboard

  1. Log in to your AppTrove dashboard
  2. Navigate to uninstall logs
  3. Confirm the uninstall event was received (typically within 24-48 hours)
Uninstall Data Processing Time

Uninstall events are not detected immediately. It typically takes 24-48 hours for uninstall data to appear in the AppTrove panel after an app is uninstalled. This is normal behavior for FCM-based uninstall tracking.

Important Notes

FCM Token Behavior
  • Token Generation: FCM tokens are generated when the app is first installed or when the token is refreshed
  • Token Refresh: Tokens can change when:
    • App is restored on a new device
    • App data is cleared
    • App is uninstalled and reinstalled
    • Token expires (rare)
  • One-Time Call: Token registration listener is called only when a new token is generated, not on every app launch
Silent Notifications Only

AppTrove uses silent push notifications solely to measure uninstalls or identify inactive users and does not use them for any other purposes. These notifications are invisible to users and don't affect app performance.

Troubleshooting

Common Issues

  • FCM token not received: Ensure Firebase is properly configured and google-services.json is in the correct location
  • Uninstall not detected: Check server logs for FCM delivery failures and verify token registration
  • Token not sent to Trackier: Ensure initializeFCM() is called after SDK initialization
  • Rate limiting: Implement proper delays between FCM sends to avoid Google's rate limits
  • Token expiration: The token refresh listener automatically handles token updates

Best Practices

  • Silent notifications: Use silent push notifications to avoid user disruption
  • Rate limiting: Implement proper delays to avoid FCM rate limits
  • Token management: Handle FCM token refresh and updates properly
  • Error handling: Implement comprehensive error handling for FCM failures
  • Security: Store FCM tokens securely
  • Call Order: Always initialize FCM after Trackier SDK initialization