Tracking App Uninstalls
This guide explains how to enable Singular to track uninstalls for your app using the Singular React Native SDK.
Prerequisites
- A Singular account with your app configured in the Singular platform.
- The Singular React Native SDK installed in your project. See SDK Installation Guide for details.
- Familiarity with retrieving APNS (iOS) or FCM (Android) tokens in React Native.
Steps to Enable Uninstall Tracking
-
Configure Uninstall Tracking in Singular
Log in to the Singular platform and navigate to your app’s settings. Follow the platform-specific setup instructions for uninstall tracking:
Ensure the configuration is complete before proceeding.
-
Retrieve the APNS or FCM Token
Use your preferred method to obtain the APNS token (for iOS) or FCM token (for Android) in your React Native app. Example libraries:
- iOS: @react-native-firebase/messaging or react-native-push-notification.
- Android: @react-native-firebase/messaging.
Code Sample
import messaging from '@react-native-firebase/messaging'; async function getPushToken() { try { const token = await messaging().getToken(); return token; } catch (error) { console.error('Error retrieving push token:', error); return null; } }
-
Pass the Token to Singular
Use the setUninstallToken method to send the APNS or FCM token to Singular. Ensure the correct token is passed based on the device platform (iOS or Android).
Code Sample
import Singular from 'react-native-singular'; async function registerUninstallTracking() { const token = await getPushToken(); if (token) { Singular.setUninstallToken(token); console.log('Uninstall token registered:', token); } else { console.warn('No token available for uninstall tracking'); } } // Call this function when your app initializes or after token retrieval registerUninstallTracking();
Platform-Specific Notes
- iOS: Ensure your app has the necessary push notification entitlements and APNS is properly configured.
- Android: Verify that FCM is set up in your Firebase console and the google-services.json file is included in your project.
Troubleshooting
- Token not registering? Confirm that the token is valid and the Singular SDK is initialized before calling setUninstallToken.
- Platform mismatch? Use platform detection to ensure the correct token type is passed:
import { Platform } from 'react-native';
if (Platform.OS === 'ios') {
// Handle APNS token
} else if (Platform.OS === 'android') {
// Handle FCM token
}