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?
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.
Yes you can there are many packages available to track uninstallation.
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.
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.
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With