为了让 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 应用程序我想知道您对此事的看法?
最佳答案
当您将“window._atrk_fired”设置为 false 时,您必须通过调用 atrk() 重新运行 fire 方法,因此您的路线更改事件应该是这样的
$rootScope.$on( "$routeChangeStart", function(event, next, current) {
console.log('setting alexa fire value to false');
window._atrk_fired = false;
atrk();
})
关于javascript - 破解 Alexa 以支持 AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34610006/