[英]How to programatically send an event to GA4 without Google Tag Manager?
I would like to send a custom event to the new Google Analytics programatically, without defining it in the GTM first.我想以编程方式将自定义事件发送到新的 Google Analytics,而不是先在 GTM 中定义它。
I am using Google Tag Manager and according to this article: https://developers.google.com/analytics/devguides/collection/ga4/translate-events我正在使用谷歌标签管理器,根据这篇文章: https : //developers.google.com/analytics/devguides/collection/ga4/translate-events
It is only possible by defining an event in the GTM itself.只有通过在 GTM 本身中定义事件才有可能。 I can not do that and would like to keep doing this using the old method, where you could just do:我不能这样做,并希望使用旧方法继续这样做,您可以这样做:
if ("ga" in window) {
var tracker = ga.getAll()[0];
if (tracker) {
tracker.send("event", eventCategory, eventAction);
}
}
How can I achieve this effect using JavaScript with the new Google Analytics (GA4)?如何使用 JavaScript 和新的 Google Analytics (GA4) 实现这种效果?
window.gtag
is undefined as I'm using GTM, and window.ga
is undefined as I'm using GA4. window.gtag
未定义,因为我使用的是 GTM, window.ga
未定义,因为我使用的是 GA4。 The only tag configured in the GTM is "Google Analytics: GA4 Configuration". GTM 中配置的唯一标记是“Google Analytics:GA4 配置”。
You have to use this syntax (and you have to use gtag snippet in page):您必须使用此语法(并且必须在页面中使用 gtag 代码段):
gtag('event', 'login', {
'method': 'Google'
});
https://developers.google.com/analytics/devguides/collection/ga4/events https://developers.google.com/analytics/devguides/collection/ga4/events
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.