首页 > 解决方案 > 如何通过 Angular 5 在单个页面中获取多个标签的谷歌分析

问题描述

我可以获得路线的谷歌分析,如果我们导航不同的路线,它正在工作,但在一个页面内我有多个标签。我想要基于标签的谷歌分析导航。请参考下面的上传图片以供参考。先感谢您

ga('create', 'UA-XXXXXX-Y', {'userId': customUserId}); // 如果“用户 ID”功能可用 ga('require', 'displayfeatures'); ga('set', 'dimension1', customUserId); //customUserId在页面级别设置维度 ga('send', 'pageview'); 在此处输入图像描述

标签: angulargoogle-analytics

解决方案


您必须为此捕获自定义事件

//Function in service.ts file  
googleEventTrack(eventCategory,eventLabel,eventAction,eventValue) {
(<any>window).ga('send', 'event', {
  eventCategory: eventCategory,
  eventLabel: eventLabel,
  eventAction: eventAction,
  eventValue: eventValue
});

}

//capture event on button click in component.ts
btnClick(){
   this.CommonService.googleEventTrack('eventCategory', 'eventLabel',
   'eventAction', 'eventValue');
}

推荐阅读