我工作的角度8,并增加了谷歌分析,以提供更好的服务给用户。但是它不断地显示以下错误:
以下是为在项目中使用google分析而添加的服务:
gaservice.service.ts
import { Injectable } from '@angular/core';
declare let gtag:Function;
@Injectable({
providedIn: 'root'
})
export class GoogleAnalyticsService {
constructor(){}
public eventEmitter(
eventCategory: string,
eventAction: string,
eventLabel: string = null,
eventValue: number = null ){
gtag('event', eventAction, {
'event_category': eventCategory,
'event_label': eventLabel,
'value': eventValue
});
}
}
发布于 2021-06-03 00:00:54
使用
(<any>window).gtag(..)
或
window['gtag'](...)
我想我可以做的是创建一个函数:
export const gtag = () => window['dataLayer'].push(arguments)
这是因为我在GA4中使用GTM,但它没有为我定义window.gtag
(参见Google Analytics Web+App event config: Error 'gtag is not defined')。
https://stackoverflow.com/questions/65038758
复制相似问题