javascript Mixpanel 匿名用户转换为已识别用户跟踪

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10728350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:50:30  来源:igfitidea点击:

Mixpanel anonymous user converts to identified user tracking

javascriptcookiestrackingmetricsmixpanel

提问by Jim Rubenstein

I'm adding Mixpanel to my web application and I'm curious about the "process" around what happens when a user transitions from "anonymous" (not logged in/registered) to "identified" (when they register / create an account on the site).

我正在将 Mixpanel 添加到我的 Web 应用程序中,我很好奇当用户从“匿名”(未登录/注册)转换为“已识别”(当他们在网站)。

If a user comes in and is new to the site, they get an anonymous UUID (according to the documentation). The documentation also says that Mixpanel can not translate between IDs at this time.

如果用户进入该站点并且是该站点的新用户,他们将获得一个匿名 UUID(根据文档)。文档还说 Mixpanel 目前无法在 ID 之间进行转换。

Does this mean Mixpanel is incapable of handling the transition of a non-registered user to a registered user, and keep track of their events from before they became a registered/identified user?

这是否意味着 Mixpanel 无法处理非注册用户到注册用户的转换,并无法跟踪他们成为注册/识别用户之前的事件?

If so, does anyone have experience with working around this? How'd you go about it?

如果是这样,有没有人有解决这个问题的经验?你是怎么处理的?

回答by loopj

As of December 2012, you can now use the mixpanel.aliasmethod call to alias two ids:

截至 2012 年 12 月,您现在可以使用mixpanel.alias方法调用为两个 ID 设置别名:

https://mixpanel.com/docs/integration-libraries/using-mixpanel-alias

https://mixpanel.com/docs/integration-libraries/using-mixpanel-alias

From the above docs:

从上面的文档:

John comes to your website, example.com, for the first time. He is assigned a randomly generated ID (perhaps 123123) by Mixpanel. Everything he does is associated with that ID.

After clicking through a few pages, he successfully signs up. On the signup confirmation page, you call mixpanel.alias("[email protected]"). This doesn't actually change his ID - he is still being identified using the random ID we originally assigned him.

What it does do is add the ID "[email protected]" to a lookup table on our end. Whenever we see data for "[email protected]", we know to remap it to 123123, his original ID.

So, you can start calling mixpanel.identify("[email protected]") on all your pages, and your events, funnels, and retention will all continue to work perfectly.

John 第一次访问您的网站 example.com。他被 Mixpanel 分配了一个随机生成的 ID(可能是 123123)。他所做的一切都与该 ID 相关联。

点开几页后,他就成功注册了。在注册确认页面上,您调用 mixpanel.alias("[email protected]")。这实际上并没有改变他的 ID - 他仍然使用我们最初分配给他的随机 ID 进行识别。

它所做的是将 ID“[email protected]”添加到我们端的查找表中。每当我们看到“[email protected]”的数据时,我们就知道将其重新映射到他的原始 ID 123123。

因此,您可以开始在所有页面上调用 mixpanel.identify("[email protected]"),并且您的事件、渠道和保留都将继续完美运行。

回答by Woody Schneider

There are ways to make this work. But what you are really asking for is a feature called distinct id aliasing, which would allow you to reference one distinct_id ID to another. Unfortunately, we don't offer that right now. This turns out to be a much harder issue than you'd expect due to the unique nature of the data-store we wrote for mixpanel.

有很多方法可以使这项工作发挥作用。但是您真正需要的是一个称为 distinct id 别名的功能,它允许您将一个 distinct_id ID 引用到另一个。不幸的是,我们现在不提供。由于我们为 mixpanel 编写的数据存储的独特性质,这比您预期的要困难得多。

In the meantime, I can give you a few strategies to get around this limitation:

同时,我可以为您提供一些解决此限制的策略:

  • When a user first comes to your website, set a distinct id for them which you generate internally. Once they register for an account, reference that distinct_id in your user detail table, and then continue to register subsequent events with that id. Each subsequent time a user auths, use the stored value as the distinct id. Hopefully when they return the cookie will still be around, and you will capture all the events without a hitch.

  • You could, also, let mixpanel give them an auto-issued distinct_id value, and then grab that at the time of registration by using mixpanel.get_property() then add that to your users table, and use that when you identify them in the future.

  • But what if they auth from one machine and then come on from another, or a different browser, or from a mobile device? Then the time in between when they hit your site and when they auth they'll be issued a new distinct_id by your site... and there is no way to alias! The solution here is a bit hackier. The only way to get that data is to log those events that were sent before the authentication (maybe server-side) and then send them via HTTP specification to the rest API with the correct distinct_id once the user auths. As long as you keep the correct time stamps, it will all appear correctly, chronologically within mixpanel. If the user never auths, then you can have the logged events time out and send them anyways.

  • 当用户第一次访问您的网站时,为他们设置一个您在内部生成的不同 ID。一旦他们注册了帐户,请在您的用户详细信息表中引用该 distinct_id,然后继续使用该 ID 注册后续事件。每次用户进行身份验证时,都使用存储的值作为不同的 id。希望当他们返回时,cookie 仍然存在,您将顺利捕获所有事件。

  • 您也可以让 mixpanel 为他们提供一个自动发出的 distinct_id 值,然后在注册时使用 mixpanel.get_property() 获取该值,然后将其添加到您的用户表中,并在将来识别他们时使用该值.

  • 但是,如果他们从一台机器上进行身份验证,然后从另一台机器、不同的浏览器或移动设备上进行身份验证呢?然后在他们访问您的网站和他们进行身份验证之间的时间,您的网站将向他们发出一个新的 distinct_id ......并且没有办法别名!这里的解决方案有点hackier。获取该数据的唯一方法是记录在身份验证(可能是服务器端)之前发送的那些事件,然后在用户身份验证后通过 HTTP 规范将它们发送到具有正确 distinct_id 的其余 API。只要您保留正确的时间戳,它就会在 mixpanel 中按时间顺序正确显示。如果用户从不进行身份验证,那么您可以让记录的事件超时并发送它们。

Would either of these work for you?

这些对你有用吗?

回答by x1a4

When a user hits your site, identify them with a unique id and save it in a cookie if they don't already have one, then use the Mixpanel IdentifyAPI call to identify them. You can persist the unique id to your database in the user's record once they have registered, so you can re-set it in the case they clear their cookies.

当用户访问您的网站时,使用唯一 ID 识别他们并将其保存在 cookie 中(如果他们还没有),然后使用Mixpanel IdentificationAPI 调用来识别他们。您可以在用户注册后将唯一 id 保存到您的数据库中的用户记录中,以便您可以在他们清除 cookie 的情况下重新设置它。

If the user clears their cookies before registering, then you would be out of luck, but that's the nature of this beast and would be an issue anywhere.

如果用户在注册之前清除了他们的 cookie,那么您将不走运,但这就是这个野兽的本性,并且在任何地方都会成为问题。