Google 未从 angular 8 个项目中记录分析事件值

Google Analytics event values not recorded from angular 8 project

我正在使用 Google 分析来跟踪用户活动。但是,即使我从服务中触发事件,事件的值也被记录为零。

遵循以下 link 的步骤:How To Properly Add Google Analytics Tracking to Your Angular Web App

我的代码:

googleanalytics.service.ts

import {Injectable} from '@angular/core';
declare let gtag:Function;


@Injectable({
  providedIn: 'root'
})
export class GoogleanalyticsService {

  constructor() { }

  public eventEmitter( 
    Eventname: string, 
    Eventcategory: string, 
    Eventaction: string, 
    Eventlabel: string = null,  
    Eventvalue: number = null ){ 
         gtag('event', Eventname, { 
                 Eventcategory: Eventcategory, 
                 Eventlabel: Eventlabel, 
                 Eventaction: Eventaction, 
                 Eventvalue: Eventvalue
               })
    }
public event2(
  
    Eventcategory: string, 
    Eventaction: string, 
    Eventlabel: string = null,  
    Eventvalue: number 
){
  gtag('send', {
    hitType: 'event',
    eventCategory: Eventcategory,
    eventAction: Eventaction,
    eventLabel: Eventlabel,
    Eventvalue: Eventvalue
  });
}
    public setGAUser(userid){
      gtag('set',{'user_id': userid}); // Set the user ID using signed-in user_id.})

    }
}

samplecomponent.ts:

this.GAService.eventEmitter('user_completed_form','user','click','user',30);

请提出一些解决方案。

gtag 中的事件具有以下语法:

gtag('event', <action>, {
  'event_category': <category>,
  'event_label': <label>,
  'value': <value>
});

你调用的第二个参数Eventname实际上是action。尝试遵循上述构造,您会发现它会正常工作。