监听通过GTM实现的JS事件,并在GA4中跟踪它

huangapple go评论73阅读模式
英文:

Listening for a JS event implemented via GTM and tracking it in GA4

问题

我的页面集成了一个提供JS SDK的应用程序。

这个SDK允许我监听事件并执行类似这样的回调函数:

function doThis() {
    // 告诉 GA4 事件发生了
}

$myApp.push(["on", "event:triggered", doThis]);

我已经按照更新的说明在我的网站上实施了GTM,并能够通过以下设置将上述代码添加到我的页面:
触发器: 在窗口加载时
标签: 自定义HTML(包含上述代码)

我还通过在“窗口加载时”创建GA4配置的标签成功实施了GA4,其中包括我的测量ID。

然而,我不明白如何跟踪通过GTM实施的上述事件在GA4中如何追踪。
我希望能够像查看页面浏览量一样查看此事件。

我想这可能很基础,但尽管我尝试了很多次,但仍然无法弄清楚。

英文:

My page integrates an app which provides a JS SDK.

This SDK allows me to listen for events and do callbacks like this one:

function doThis() {
    // tell GA4 the event happened
}

$myApp.push(["on", "event:triggered", doThis]); 

I've implemented GTM on my website following the updated instructions, and I am able to push the above code onto my page by using this setup:
Trigger: On Window loaded
Tag: Custom HTML (with the above code)

I've also been able to implement GA4 through GTM by creating a Tag for the GA4 Configuration with my Measurement ID (on Window Loaded as well).

However, I do not understand how the above event (which I've implemented through GTM) can be tracked in GA4.
I would like to be able to see this event the same way I am able to view page views for instance.

I imagine this is probably basic, but I've not been able to figure it out despite my attempts.

答案1

得分: 1

你说得对。这确实很基础。在你的回调函数中,你只需要将事件推送到dataLayer,就像这样:

window.dataLayer = dataLayer || [];
dataLayer.push({event: "给它起个有意义的名字"});

然后在Google Tag Manager中,你可以创建一个触发器,如下所示:

监听通过GTM实现的JS事件,并在GA4中跟踪它

就是这样。这个触发器将由你的回调函数触发。你还可以向该对象添加更多字段,它们将在DL事件触发器上可用。

这里了解更多关于DL的信息。

英文:

You're correct. This is basic indeed. All you need in your callback is to push an event to the dataLayer. Something like:

window.dataLayer = dataLayer || [];
dataLayer.push({event: "name-it-meaningfully"});

Then in GTM, you make a trigger like so:

监听通过GTM实现的JS事件,并在GA4中跟踪它

That's it. This trigger will be triggered by your callback. You can add more fields to that object and they will be available on the DL Event trigger.

Read more on DL here.

huangapple
  • 本文由 发表于 2023年3月4日 05:17:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631949.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定