In a Node & Express.js application, how can I check whether the application is installed on the user's mobile phone or not? I only have the user's mobile number. I know something called "deep-linking" or "customer URL scheme" can help. But I don't know much about it. Can anyone help me with some more details or resources?
Any kind of suggestions and opinions will be appreciated. Thank you.
CodePudding user response:
You can tracks app uninstalls in two ways:
Silent Push Notification - By sending a silent push notification daily
Real-time - As soon as a user uninstalls the app. This real-time tracking is available only for Android devices.
Silent Push Notifications (iOS & Android)
A silent notification is a simple, yet effective, mechanism to check token validity. An invalid token usually indicates that the app has been uninstalled. You can use silent push notifications to track application uninstalls for both, Android and iOS applications. A silent push notification contains an empty message that is sent to the user's device via Firebase Cloud Messaging (FCM) server for Android devices or Apple Push Notification service (APNs) for iOS devices.
Real-Time Uninstall Tracking (Android)
Check that the Android app is integrated with Firebase Analytics for real-time uninstall tracking.
When a user uninstalls an app from their Android device, a Firebase event called app_remove tracks this app uninstall. You can push this event to your server using the Firebase cloud functions
Implement Real-Time Uninstall Tracking
Real-time uninstall tracking is a four-step process :
Set up a common identifier in your app
Set the app_remove event as a conversion event in Firebase
Use the Firebase cloud function to send uninstall information to your server
Set Up a Common Identifier Add the following code to your app to set up a common identifier between Firebase and your server.
Java (Client Side Implementation)
private FirebaseAnalytics mFirebaseAnalytics;
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.setUserProperty("uuId","Your server clientId");
Set Up Conversion Event Using Firebase
To set up real-time uninstall, check that a conversion event is set up on the Firebase dashboard. Firebase analytics track an event called app_remove, which is one of the automatically collected Firebase events. The app_remove event is an Android-only event that is tracked when an application package is removed or uninstalled from the device, irrespective of the installation source.
To set up conversion, perform the following steps:
Select the Firebase project that is integrated with the Android app. From the Firebase dashboard, select Analytics > Events. Enable the Mark as conversion toggle for app_remove.
Create a Cloud Function
After the conversion is set up, use the Cloud Function for Firebase to create a function and send the app_remove data to your server.
To create and publish a cloud function using Node JS, perform the following steps:
Open a terminal. Set up Node.js and the Firebase CLI.
Run npm install -g firebase tools.
To initialize Firebase SDK for Cloud Functions, run firebase login. From your Firebase project directory, run firebase init functions. Select Javascript as a language option. Open index.js and add the following code:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const https = require('https');
var request = require('requestretry');
admin.initializeApp();
exports.sendAndroidUninstallToServer =
functions.analytics.event('app_remove').onLog((event) => {
//console.log("Event is: " JSON.stringify(event));
function myRetryStrategy(err, response, body, options) {
// retry the request if we had an error or if the response was a
'Bad Gateway'
return !!err || response.statusCode === 503;
}
var uuId = event.user.userProperties.uuId.value;
// This is where the UUD ID of the user who uninstalled the app is passed as an identifier in the API call.
const data = JSON.stringify({
"d": [{
"objectId": uuId,
"type": "event",
"evtName" : "App Uninstalled",
"evtData": {
}
}]
});
//send data to your server
}
, function (err, response, body) {
// this callback will only be called when the request succeeded or
after maxAttempts or on error
if (response && response.statusCode === 200) {
console.log("Response Body: " JSON.stringify(body));
console.log('The number of request attempts: '
response.attempts);
return 0;
}else{
console.log("err: " err " ,response: "
JSON.stringify(response) " , body: " JSON.stringify(body));
return 1;
}
});
});