Google Analytics Web + App事件配置:错误“未定义gtag" [英] Google Analytics Web+App event config: Error 'gtag is not defined'
问题描述
我正在尝试为网站设置Google Analytics(分析)App + Web的电子商务事件配置.请参阅文档此处.
I'm trying to setup ecommerce event configuration of Google Analytics App+Web for a website. Refer to the documentation here.
由于电子商务配置有很多自定义代码,因此我无法使用通用的GA App + Web网络事件模板,因此在这种情况下,我使用的是自定义HTML标签.
Because there is a lot of custom code for the ecommerce configuration, I cannot use the general GA App+Web webevent template, so instead I'm using a custom HTML-tag in this case.
作为第一个测试,我尝试触发以下简单事件:
As a first test, I tried to fire the following simple event:
<script>
gtag('event', 'blabla', {
'test_param1': 'test_value_1'
});
</script>
但是,该事件未正确发送到GA;而是返回控制台中的以下错误:
However, the event is not correctly sent to GA; instead, the following error in the console is returned:
未捕获的ReferenceError:未定义gtag
要复制,请参见以下页面: https://www.hema.nl/mooi-gezond/make-up/make-up-accessoires/toilettassen-1/toilettas-11830901.html
To reproduce, see the following page: https://www.hema.nl/mooi-gezond/make-up/make-up-accessoires/toilettassen-1/toilettas-11830901.html
其他信息:
- 通过GTM(通过GA App + Web配置模板标记)(成功)完成GA App + Web基础初始化.
- 我还通过GA App + Web webevent模板标记通过GTM配置了其他一些(简单的非电子商务)GA App + Web事件,并将这些事件成功发送到了GA.
有人知道这是怎么回事,为什么会出现控制台错误,为什么事件不会发送到GA?
Does anyone know what's going wrong, why the console error appears and why the event is not sent to GA?
推荐答案
已找到问题的原因.问题似乎是,如果使用GTM App + Web基本模板标记完成了App + Web基本设置,则gtag()无法正常工作.相反,应该先将事件推送到GTM数据层,然后再使用GTM App + Web事件模板将事件发送到Google Analytics(分析).
The cause of the problem has been found. The problem seemed to be that gtag() does not work if the App+Web base setup is done with the GTM App+Web base template tag. Instead, an event should first be pushed to the GTM datalayer, and then the GTM App+Web event template should be used to send the event to Google Analytics.
非常感谢Gino(在Merkle工作)解决了这个问题!
Lots of thanks Gino (working at Merkle) for fixing the issue!
这篇关于Google Analytics Web + App事件配置:错误“未定义gtag"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!