2016-08-03 48 views
0

跟蹤我已經安裝瀏覽量下方角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'); 
} 

我也沒有收到任何錯誤或警告,只是這個事件沒有得到註冊。

+0

安裝適用於Chrome的GA調試器,以查看事件是否經過,或者檢查您的開發控制檯或實時報告 – nyuen

回答

0

我想 'trackEvent' 方法可以幫助:

ga.push(['_trackEvent', event, action, param3, param4]);

假設GA是一個數組。

+0

ga不是數組,它的功能不能使用ga.push –

+0

好,但你嘗試過使用'_trackEvent'嗎? – Araknid

+0

'_trackEvent'是基於ga.js的較老的語法。這不起作用 – nyuen