Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Functions for Firebase: can you detect app uninstall?

Is it possible to trigger a Cloud Function when the user uninstalls the app, so that we can clean up the anonymous user realtime database entry?

like image 258
Daniele B Avatar asked Aug 17 '17 20:08

Daniele B


People also ask

How can I tell if an Android app has been uninstalled?

You can detect app uninstalls by sending 'silent' push notifications. Silent push notifications are those notifications that aren't rendered on the user's device. You could send a silent push notification daily to all the devices with your app to track uninstalls.

Can I catch an event when application is uninstalled in react native?

Yes you can there are many packages available to track uninstallation.

How do Firebase cloud functions work?

Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment.

When should you not use Firebase?

Firebase is not made for processing complex queries as it relies on a flat data hierarchy. Complicated queries like reversing the order of certain items cannot be executed using Firebase. On top of that, even when you go offline, your app might begin to underperform due to the concurrency.


1 Answers

You can detect app uninstall for Android as an automatically collected Analytics event called app_remove. Then you could trigger a Cloud Function to run when that event occurs. You would also need to use the Firebase Admin SDK to access the database. Check out some of the Cloud Functions for Firebase GitHub samples to see examples of using Analytics triggers and using the Admin SDK. The function could work something like this:

exports.appUninstall = functions.analytics.event('app_remove').onLog(event => {
  const user = event.user; // structure of event was changed            
  const uid = user.userId; // The user ID set via the setUserId API.

  // add code for removing data
});
like image 56
Jen Person Avatar answered Oct 05 '22 13:10

Jen Person