Google标签管理器 - 如何立即收集?
在我的网页中,有以下测量
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速答案:是的,您可以做到。您可以告诉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 valuebeacon
in your GTM tag. You can find more on it here: https://www.simoahava.com/analytics/fire-trigger-when-user-about-to-leave-page/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.