![](/img/trans.png)
[英]What is the canonical way to manually fire page_view in Google Tag Manager and Google Analytics 4 (GA4)?
[英]How to programatically send an event to GA4 without Google Tag Manager?
我想以編程方式將自定義事件發送到新的 Google Analytics,而不是先在 GTM 中定義它。
我正在使用谷歌標簽管理器,根據這篇文章: https : //developers.google.com/analytics/devguides/collection/ga4/translate-events
只有通過在 GTM 本身中定義事件才有可能。 我不能這樣做,並希望使用舊方法繼續這樣做,您可以這樣做:
if ("ga" in window) {
var tracker = ga.getAll()[0];
if (tracker) {
tracker.send("event", eventCategory, eventAction);
}
}
如何使用 JavaScript 和新的 Google Analytics (GA4) 實現這種效果?
window.gtag
未定義,因為我使用的是 GTM, window.ga
未定義,因為我使用的是 GA4。 GTM 中配置的唯一標記是“Google Analytics:GA4 配置”。
您必須使用此語法(並且必須在頁面中使用 gtag 代碼段):
gtag('event', 'login', {
'method': 'Google'
});
https://developers.google.com/analytics/devguides/collection/ga4/events
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.