1

The mixpanel api uses success callbacks to trigger code after a tracking event is completed, so that you can be sure that the event is logged before running your next function, like:

leavePage = function(){ window.location = 'http://google.com'; }
mixpanel.track('event', null, leavePage)

I would like to do the same thing with an alias call, like:

mixpanel.alias('am-i-done-yet@example.com', leavePage)

The mixpanel docs don't seem to mention any more than one argument to alias, I guessed at the above undocumented API without success. Anyone know of workarounds to trigger a success event when aliasing is complete?

4

1 回答 1

2

mixpanel javascript 库不支持对别名调用的回调。但是,您可以通过向 REST api 发送请求并使用任何框架注册回调来实现该效果。

https://mixpanel.com/help/reference/http#distinct-id-alias

实际上,由于别名调用是根据跟踪调用来实现的,因此您应该能够通过以下代码避免手动向别名调用提供不同的 id 和令牌。

var leavePage = function(){ window.location = 'http://google.com'; }
var registerEvent = function(){ mixpanel.track('event', null, leavePage); }
mixpanel.track('$create_alias', {'alias': 'am-i-done-yet@example.com'}, registerEvent);

这将对 mixpanel 进行两次调用(一次注册别名,一次注册事件),然后将导致页面重定向。

于 2013-11-27T20:00:40.943 回答