英文:
GA4 Implementation alongside Turbolinks (duplicate page_view)
问题
Running on Rails 5.2.6 - Turbolinks 5.1.1 - 我正在使用以下代码将GA4 Google Tag嵌入到网站中
<script async src="https://www.googletagmanager.com/gtag/js?id=XXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
document.addEventListener('turbolinks:load', event => {
if (typeof gtag === 'function') {
gtag('config', 'XXXX', {
'page_path': location.pathname + location.search,
'page_location': event.data.url
});
}
});
</script>
在使用Google Tag Assistant站点时,一切都在第一页访问时正常工作 - "page_view"在"CONFIG"中被注册。
但是,在页面更改时,我会收到额外的“page_view”事件,由“History Change”注册 - 用于更改浏览器的后退按钮。
在Universal Analytics中我没有遇到这种行为.. ?
英文:
Running on Rails 5.2.6 - Turbolinks 5.1.1 - i'm embedding GA4 Google Tag to the site using the following code
<script async src="https://www.googletagmanager.com/gtag/js?id=XXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
document.addEventListener('turbolinks:load', event => {
if (typeof gtag === 'function') {
gtag('config', 'XXXX', {
'page_path': location.pathname + location.search,
'page_location': event.data.url
});
}
});
</script>
using the google Tag Assistant site - everything works fine on first page visit - "page_view" is registered in the "CONFIG".
However I am getting an additional "page_view" event firing on page change registered by "History Change" - which is used to change the back button for the browser.
I don't get this behaviour in Universal Analytics.. ?
答案1
得分: 0
在GA4管理/数据流中,原来有一个默认设置,即在浏览器历史更改时发送page_view事件。
您可以在高级面板中禁用此设置。
英文:
So
Turns out in GA4 admin / data streams
There is a default setting to send a page_view event on change of browser history
You can disable in the advanced panel
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论