Mixpanel with EmberJS

别说谁变了你拦得住时间么 提交于 2019-12-03 20:43:10

Track routing changes for a service like Mixpanel or Google Analytics with EmberJS reopen the router and overwrite the didTransition method call the mixpanel/analytics api inside the next Ember run loop.

Ember.Router.reopen({
  didTransition: function(paths){
    this._super(paths);
    Ember.run.next(function(){
      path = window.location.href;
      mixpanel.track("pageview", {"url": path });
    });
  }
});

Here is a jsbin

Final Solution

$(window).on('hashchange', function(){
    mixpanel.track("pageview", {"url": window.location.href });
});

Ember.Application.initializer({
    initialize: function(container, application) {
        mixpanel.track("pageview", {"url": window.location.href });
    }
});

Now I get initial page loads tracked as well as transitions within the application.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!