混合面板与EmberJS [英] Mixpanel with EmberJS

查看:98
本文介绍了混合面板与EmberJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我开始写这个问题,并在写作时最终解决了这个问题。我会离开这里,希望它会帮助别人。

Note: I began writing this question, and in writing it up ended up solving the problem. I'll leave it here and hopefully it will help someone else.

我一直在这个墙上冲我的头一会儿,不断得到不一致的结果。

I've been pounding my head against the wall with this for a while now and keep getting inconsistent results.

尝试1 (从 here

App.ApplicationController = Ember.Controller.extend({ 
    routeChanged: function (){
        mixpanel.track("pageview", {"url": window.location.href });
    }.observes('currentPath')
});

我不得不偏离这个例子,因为 mixpanel.track_pageview() code>已被弃用。这导致了不正确的位置记录,因为我无法找到一种方法来获得一旦转换重写URL的新哈希路径,并且URL此时尚未更新。

I had to deviate from the example since mixpanel.track_pageview() is deprecated. This resulted in incorrect location logging since I can't find a way to get what the new hash path will be once the transition rewrites the URL, and the URL hasn't been updated at this point.

尝试2

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

当URL哈希更改时,此功能起作用,但是现在我的网站没有得到任何跟踪首先加载。

This works when the URL hash changes, but now I don't get any tracking when the site is first loaded.

推荐答案

跟踪混合面板 Google Analytics(分析)与EmberJS重新打开路由器并覆盖 didTransition 方法在下一个Ember运行循环中调用mixpanel / analytics api。

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 });
    });
  }
});

这是一个 jsbin

这篇关于混合面板与EmberJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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