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

问题描述

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

以下是来自以下链接的步骤:How To Properly Add Google Analytics Tracking to Your Angular Web App

image of event from Google Analytics

我的代码

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,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',30);

请提出一些解决方案。

解决方法

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

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

您称为 Eventname 的第二个参数实际上是action。尝试遵循上面的构造,您将看到它可以正常工作。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...