为了让 Alexa 在基于 Angular 的应用程序上工作,我下载了 Alexa 代码片段并对其进行了分析。
似乎 Alexa 依赖于这个功能:
fire: function (e) {
this.user_cookie_v = this.muc();
this.map(e, function (e, t) {
this.opts[e] = t
});
// this.fired() check if "window._atrk_fired" is truthy
if (this.fired()) {
return
}
window._atrk_fired = true;
var t = new Image(1, 1);
t.alt = "alexametrics";
t.src = this.gen_url();
this.cloudfront.fire()
}
因为,在 Angular 应用程序中,页面没有重新加载,事件 fire() 仅在“window._atrk_fired”保持真实后触发一次。
我必须添加此代码以模拟页面重新加载:
$rootScope.$on( "$routeChangeStart", function(event, next, current) {
console.log('setting alexa fire value to false');
window._atrk_fired = false;
})
我知道这个 hack 不是很可靠,因为 Alexa 可能会更改 pageView 跟踪策略。但我的目标是查看 Alexa 是否可以跟踪 Angular 应用程序。我想知道您对此事的看法?