gpt4 book ai didi

javascript - Google Analytics 在单页应用程序上拆分 session (Rogue Referral Problem)

转载 作者:行者123 更新时间:2023-12-03 07:11:14 25 4
gpt4 key购买 nike

我们正在使用 gatsby 来开发我们的网站,我正在使用 gatsby-plugin-google-tagmanager 插件来触发 google analytic events..

我们面临的一个问题是,当用户从 utm 链接访问我们的网站时, session 似乎在他登陆页面的同一秒内 split 。

到目前为止我做了什么

使用 gatsby-route-change 触发器触发 Page View Google Analytics: Universal Analytics 标签。

GA调试报告

有一点看起来不正常的是,在每次路由更改时,使用 GA Debug 工具,都会创建一个新的 Creating new tracker 日志。

enter image description here

我尝试解决此问题的方法

阅读一篇文章,在单页应用程序中,您可能会得到 pagelocationreferrer 属性的错误值,所以这愚弄了谷歌分析每次都创建一个新 session ,因此这可能是 session 中断的原因。

我试图做的是覆盖 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;
}

对此有什么想法吗?这种行为是否有可能 split 我们的 session ?您还有什么推荐的吗?

最佳答案

https://www.simoahava.com/gtm-tips/fix-rogue-referral-problem-single-page-sites/

这篇文章回答了这个问题。

With Google Tag Manager, every single Universal Analytics Tag that fires on the site creates a new, unique tracker object. This means that the Document Location field is updated with every Tag you fire, which is a problem if the URL changes due to browser history manipulation. Thus you can end up with a situation where the first Universal Analytics Tag has gclid in the URL, attributing the session to AdWords, but the next pageview doesn’t have this in the URL anymore, as you would not include it in the “virtual” pageview path names. Instead, since gclid is no longer in the URL, GA looks at the HTTP referrer of the page to see what the previous page was for attribution. It finds google.com, as you came from the search engine (HTTP referrer is not updated when manipulating the URL with the browser History API). Thus a new session starts with attribution to Google Organic! I’ve dubbed this as the Rogue Referral problem.

解决方案

手动设置文档位置以防止恶意引用

  1. 创建脚本将登陆URL保存在dataLayer中

    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
    originalLocation: document.location.protocol + '//' +
    document.location.hostname +
    document.location.pathname +
    document.location.search
    });
  2. 创建脚本变量以获取当前页面。 (如果你不需要哈希删除它)

    function() {
    return window.location.pathname + window.location.search +
    window.location.hash
    }

通过手动设置字段位置和页面向所有 Universal Analytics 添加变量

enter image description here

关于javascript - Google Analytics 在单页应用程序上拆分 session (Rogue Referral Problem),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58842970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com