使用角度2设置Google Analytics分析事件跟踪

时间:2016-08-03 11:10:02

标签: javascript angularjs angular google-analytics

我设置了网页浏览跟踪角度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');
}

我也没有收到任何错误或警告,只是这个事件没有被注册。

1 个答案:

答案 0 :(得分:0)

我认为'trackEvent'方法可以提供帮助:

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

假设ga是一个数组。

相关问题