Cloud Functions for Firebase: can you detect app uninstall?

前端 未结 1 969
旧时难觅i
旧时难觅i 2020-12-09 12:10

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?

相关标签:
1条回答
  • 2020-12-09 12:50

    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
    });
    
    0 讨论(0)
提交回复
热议问题