适用于Firebase的云功能:您可以检测到应用卸载吗?

时间:2017-08-17 20:26:52

标签: firebase firebase-realtime-database google-cloud-functions

当用户卸载应用程序时是否可以触发云功能,以便我们可以清理匿名用户实时数据库条目?

1 个答案:

答案 0 :(得分:16)

您可以检测到Android的app卸载为automatically collected Analytics event,名为app_remove。然后,当事件发生时,您可以trigger a Cloud Function运行。您还需要使用Firebase Admin SDK来访问数据库。查看部分Cloud Functions for Firebase GitHub samples,查看使用Google Analytics触发器和使用Admin SDK的示例。该函数可以像这样工作:

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
});