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

时间:2022-02-27 15:16:57

I have setup pageviews tracking with angular 2 & below is my code, but not sure how to set event tracking:

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

Above code to get page view is working fine, but not below event tracking code

以上代码获取页面视图工作正常,但不低于事件跟踪代码

// 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');
}

I am also not getting any error or warning, just this event is not getting registered.

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

1 个解决方案

#1


0  

I suppose 'trackEvent' method could help:

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

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

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

Assuming ga is an array.

假设ga是一个数组。

#1


0  

I suppose 'trackEvent' method could help:

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

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

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

Assuming ga is an array.

假设ga是一个数组。