[英]Setup google analytics event tracking with angular 2
我的代码中设置了角度为2且以下的设置综合浏览量,但不确定如何设置事件跟踪:
// app.component.ts -> this is working fine
declare let ga:Function;
export class App {
constructor(public router: Router) {
this.router.events.subscribe((event:Event) => {
if(event instanceof NavigationEnd) {
ga('send', 'pageview', event.urlAfterRedirects);
}
});
}
}
上面的代码获得页面视图很好,但下面的事件跟踪代码却不能正常工作
// spreadsheet.component.ts
declare let ga:Function;
updateContact(contact) {
// http call
.....
// On success, this should get fired
ga('send', 'event', 'update_contact', 'update', 'Update contact requested');
}
我也没有收到任何错误或警告,只是此事件没有注册。
我想'trackEvent'方法可以帮助您:
ga.push(['_trackEvent', event, action, param3, param4]);
假设ga是一个数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.