我们正在使用gatsby来开发我们的网站,我正在使用gatsby-plugin-google-tagmanager插件来启动google analytic events。
我们面临的一个问题是,当用户从utm链接访问我们的站点时,session似乎与他在页面上登陆的那一秒完全相同。
我到目前为止做了什么,
使用Page View触发器触发Google Analytics: Universal Analytics标记。
GA调试报告
一件似乎不正常的事情是,在每次更改路由时,使用GA Debug工具都会创建一个新的Creating new tracker日志。

我试图修复这个的方法
阅读一篇文章,在单页应用程序中,您可能会得到page、location和referrer属性的错误值,因此这会使谷歌分析每次创建一个新会话,因此这可能是会话中断的原因。
我想要做的是覆盖GA标记中的这些值。然而,这似乎并没有解决这个问题。
// Location override gtm variable
function () {
return window.document.location.protocol + '//' +
window.document.location.hostname +
window.document.location.pathname +
window.document.location.search
}
// Referrer override gtm variable
function () {
return window.history.state.referrer
}
// Page override gtm variable
function() {
var path = window.location.pathname + window.location.search + window.location.hash
var index = path.indexOf('?');
if(index > -1){
path = path.substring(0, index);
}
return path;
}对此有什么想法吗?这种行为有可能分裂我们的会话吗?你还有什么推荐的吗?
发布于 2020-10-18 22:01:21
https://www.simoahava.com/gtm-tips/fix-rogue-referral-problem-single-page-sites/
本文回答了这个问题。
与谷歌标签管理器,每一个通用分析标签激发在网站上创建一个新的,唯一的跟踪对象。这意味着您触发的每个标记都会更新Document字段,如果由于浏览器历史操作而导致URL更改,这将是一个问题。因此,您可能会遇到这样的情况,即第一个Universal标记在URL中有gclid,将会话归因于AdWords,但是下一个页面视图不再在URL中使用,因为您不会将它包含在“虚拟”页面视图路径名称中。相反,由于gclid不在URL中,GA会查看页面的HTTP引用程序,以查看上一页用于属性的内容。它会找到google.com,因为您来自搜索引擎(HTTP在使用browser History API操作URL时不会更新)。因此,一个新的会议开始了归于谷歌有机!我把这称为“盗贼推荐问题”。
溶液
手动设置文档位置以防止盗用引用
window.dataLayer = window.dataLayer连体[];window.dataLayer.push({ originalLocation: document.location.protocol + '//‘+ document.location.hostname + document.location.pathname + document.location.search });
函数(){返回window.location.pathname + window.location.search + window.location.hash }
通过手动设置字段、位置和页面,向所有通用分析添加变量

https://stackoverflow.com/questions/58842970
复制相似问题