I have setup pageviews tracking with angular 2 & below is my code, but not sure how to set event tracking:
// 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.
I suppose 'trackEvent' method could help:
ga.push(['_trackEvent', event, action, param3, param4]);
Assuming ga is an array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.