通过Firebase函数添加自定义用户属性 [英] Add Custom user Property through firebase function

本文介绍了通过Firebase函数添加自定义用户属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前在我们的实时数据库中,每个 uid 都有一个 planDetails 节点,该节点具有 startDate endDate planType .

Currently in our realtime database, we have a planDetails node for each uid that has fields like startDate, endDate, planType.

我想跟踪启用了高级计划的用户数量.

I want to track the number of users whose premium plan is active.

我正在尝试通过使Firebase函数每天运行并将布尔自定义用户属性(例如 isPremiumActive 更新为true或false)来实现此目的.

I am trying to do this by making a firebase function that runs daily and updates a boolean custom user property, say isPremiumActive, to either true or false.

我不能仅跟踪购买了高级计划的用户,因为有很多人只接受一次该计划,然后又不续签该计划.因此,单词"有效"

I cannot just track the users who have purchased the premium plan because there are many who take the plan once and then don't renew it. Hence the word 'Active'

我认为可以通过firebase SDK中的 setUserProperty 函数来实现但是事实证明,我们只能在用户登录后使用它.

I thought this could be achieved through the setUserProperty function in firebase SDK but turns out we can only use it when the user is logged in.

之所以得出这个结论,是因为这种分析方法没有使用任何类型的userID作为参数,而是看到它主要在经过身份验证的用户会话中使用

然后,我尝试在Google Analytics(分析)上设置自定义属性,但我想这也遵循相同的趋势.另外,我还没有找到解决方法,以解决如何通过firebase函数更新分析数据的问题.

Then I tried to set custom properties on Google analytics but I guess that too follows the same trend. Also, I am yet to find a solution to how I will update the analytics data through the firebase function.

因此,基本上,我在这里处于死胡同,如果有人可以提供替代解决方案或对我错过的事情有所了解,我会很高兴

So basically I am on a dead-end here and would be happy if someone could provide an alternate solution or throw light on something that I missed out

推荐答案

我能够通过以下功能向分析端点发出提取请求来实现此目的.我知道不建议这样做,但是可以完成工作.

I was able to do this by making a fetch request to the analytics endpoint by making a function like this. I know this is not recommended but it gets the job done.

let hitGA = () => {
  const GA_TRACKING_ID = "your GA tracking ID"
  const GA_CLIENT_ID = "steps to get this will be given in the resources below"

  const event = {
    category: "pricing",
    action: "counted",
    label: "num_active_users",
    value: 71
  }
  let request = new XMLHttpRequest();
  let message = 
  `v=1&tid=${GA_TRACKING_ID}&cid=${GA_CLIENT_ID}&aip=1&ds=add-on&t=event&ec=${event.category}&ea=${event.action}&el=${event.label}&ev=${event.value}`

  request.open("POST", "https://www.google-analytics.com/collect", true);
  request.send(message);

}

P.S.如果您想知道我是如何迷失于solutiona和其他参考文献的,请阅读

P.S. if you are curious to know how I stumbled into the solutiona and other references, read this post

这篇关于通过Firebase函数添加自定义用户属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆