简体   繁体   English

如何在没有 Google Tag Manager 的情况下以编程方式将事件发送到 GA4?

[英]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.

相关问题 在 Google 跟踪代码管理器和 Google Analytics 4 (GA4) 中手动触发 page_view 的规范方法是什么? - What is the canonical way to manually fire page_view in Google Tag Manager and Google Analytics 4 (GA4)? 带有GA的Google跟踪代码管理器 - Google Tag Manager with GA 如何获取Google跟踪代码管理器事件跟踪以发送到Google Analytics(分析)? - How to get Google Tag Manager Event Tracking to send to Google Analytics? 如何在 Angular 中将页面查看事件发送到 Google 跟踪代码管理器 - How to send Page View Event to Google Tag Manager in Angular 如何在服务器上使用新的 Google Analytics (GA4) 设置自定义事件跟踪? - How to setup custom event tracking with new Google Analytics (GA4) on the server? Google Analytics Data API (GA4) 如何使用runRealtimeReport function? - Google Analytics Data API (GA4) How to use runRealtimeReport function? 如何在 Google Analytics(分析)4 (GA4) 媒体资源中添加引荐排除项 - How to add referral exclusions in Google Analytics 4 (GA4) properties ga() function 谷歌分析在谷歌标签管理器中作为标签实现 - ga() function Google Analytics implemented as a tag in Google Tag Manager 将有效的广告系列事件数据发送到Google Analytics(分析)或跟踪代码管理器 - Send Active Campaign event data to Google Analytics or Tag Manager 如何使用Google跟踪代码管理器和GA增强型电子商务跟踪产品的几个类别? - How to track several catagories for a product with Google Tag Manager and GA Enhanced Ecommerce?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM