【问题标题】:How to get user email using firebase analytics event parameter?如何使用 Firebase 分析事件参数获取用户电子邮件?
【发布时间】:2021-02-03 07:36:35
【问题描述】:

我正在后端部分使用 Firebase 制作应用程序。用户可以使用谷歌账号登录myApp,并可以备份自己的数据。

当用户卸载 myApp 时,我想在云端删除一些文档。
collection ID 是用户电子邮件。 所以我需要知道用户电子邮件,但我不知道如何获取。

exports.appUninstall = functions.analytics.event("app_remove").onLog((event)=>{
  const userEmail = event.user.email;
  database.doc(userEmail + "/user_logged_in").delete();
  return console.log("Deleted user_logged_in because user uninstalled app");
});

【问题讨论】:

    标签: firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    我认为您目前的结构不可能做到这一点。正如你所看到的hereonLog() 返回一个AnalyticsEvent 对象,其中包含一个UserDimensions 对象,但是,该对象存储userId 和一个带有userProperties 的对象。

    我不能肯定这个userProperties 会存储您用户的电子邮件,以便您可以在 Firestore 中获取,因此您需要对此进行测试。如果没有,您将不得不找到一种方法来获取带有 userId 的用户文档,也许可以通过在创建时将其添加到文档本身。

    如果您将 documentId 更改为 userId 而不是 email,这会更容易,如果您这样做,您可以简单地使用提到的事件 userId 来获取文档并将其删除。

    【讨论】:

    • 哇,刚才我已经使用userId 解决了这个问题。哈哈。我错过了setUserId()的方法,但我找到了答案here
    猜你喜欢
    • 2018-12-19
    • 2023-01-13
    • 2017-05-30
    • 2018-11-28
    • 1970-01-01
    • 2012-02-09
    • 2020-11-28
    • 2018-03-03
    • 2019-06-25
    相关资源
    最近更新 更多