[英]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.