Google标签管理器 - 如何立即收集?

发布于 2025-02-07 13:29:21 字数 345 浏览 0 评论 0原文

在我的网页中,有以下测量

const data = {
    event: "FreeTrial-RegistrationLoginDone",
    eventContext: "additional info"     
};
window.dataLayer.push(data);

结果是,我需要在此测量后立即从此页面重定向,并且在将推入window.datalayer和自动调用API端点之间存在几秒钟的延迟。 /collect。该网页迫不及待要这么长时间。是否有一个选项可以立即提示GTM调用/collect

In my web page there is the following measurement

const data = {
    event: "FreeTrial-RegistrationLoginDone",
    eventContext: "additional info"     
};
window.dataLayer.push(data);

The issue is, I need to redirect from this page right after this measurement and there is a several second delay between pushing into window.dataLayer and automatic calling the API endpoint /collect. The web page cannot wait this long. Is there an option to prompt GTM to call /collect immediately?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼睛会笑 2025-02-14 13:29:21

快速答案:是的,您可以做到。您可以告诉Analytics.js库在调用时将请求发送“ Syncly”。这是通过将“ transport”的字段设置为GTM标签中的值BEACON来实现的。您可以在此处找到更多信息: https ://www.simoahava.com/analytics/fire-trigger-when-user-user-user-about-to-leave-page/

“在此处输入图像描述”

通常情况下,这是成功发生的,就在重定向之前谢谢页面。我们通常在这里要做的是要求开发人员将此推向下一页,并确保它不会在重新加载或直接击中Themphyou页面上。

另外,GA4引入了某些批处理逻辑,它延迟了调用,以尝试在一个网络请求中合并多个事件。但是,此延迟逻辑应使用onBeforeunload或类似的回调,以确保即使页面已导航,它们仍会发送请求。我建议您首先调试此屏幕过渡并检查您的网络选项卡,以确保在重定向上确实丢失了收集请求。

Quick answer: yes, you can do it. You can tell analytics.js library to send the request "syncly", right when it's called. This is achieved by setting the field called transport to the value beacon in your GTM tag. You can find more on it here: https://www.simoahava.com/analytics/fire-trigger-when-user-about-to-leave-page/

enter image description here

Normally this happens on success, right before the redirection to the thank you page. What we normally do here is ask the developers to move this push to the next page and make sure it doesn't fire on reloads or direct hits to the thankyou page.

Also, GA4 introduces certain batching logic where it delays the calls to try to consolidate multiple events in one network request. This delaying logic, however, should use the onbeforeunload or a similar callback to make sure they still send the request even if the page is navigated from. I would suggest first debugging this screen transition and checking your Network tab to make sure that the collect request is indeed being lost on redirect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文