使用 onbeforeunload 事件和 Google Analytics 来记录页面退出,从而更准确地记录用户在页面/网站上的时间

发布于 2024-11-10 15:01:18 字数 1835 浏览 6 评论 0原文

我一直在尝试研究 Avinash Kaushik 在他的书 Web Analytics 2.0 中提出的 hack。他提出了一个问题,即大多数网络分析工具无法记录用户在网站上访问的最后一个页面或他们访问的唯一页面上花费的时间。换句话说,如果用户访问页面 1,则会创建一个时间戳,显示他们到达该页面的时间,当他们访问页面 2 时,会创建第二个时间戳。在第 1 页上花费的时间可以通过时间戳 2 - 时间戳 1 来计算。但是,如果用户关闭浏览器窗口或离开网站,则无法在第 2 页上记录时间。以下是 Kaushik 上此问题的链接.net

standard-metrics-revisited-time-on-page-and-time-on-site

一种建议的黑客方法是使用 window.onbeforeunload 事件调用方法并将页面卸载时间推送到 google分析。所以我尝试了以下代码 -

window.onbeforeunload = capturePageExit;
function capturePageExit()
  {
    _gaq.push(['_trackPageview', '/page-exit?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer]);
    return("You are about to close this page");
  }

使用 firebug 我可以看到请求了正确的 __utm.gif 图像,并且正确的参数被发送到谷歌分析。但显然现在存在一个问题,即在每个页面卸载时都会调用此方法,因此每个访问者都会显示从 page1 ->页面退出->第2页->页面退出->第3页->页面退出...但我应该获得更准确的网站阅读时间,对吧?

然而,这是以牺牲准确的导航摘要数据为代价的,因此不是一个好的解决方案。如果我能知道 - 用户是否单击了关闭浏览器/选项卡按钮或正在离开我的网站,然后记录页面退出,那就太好了。

我找不到大量关于如何解决这个问题的信息,有很多关于在解释谷歌分析(可能还有大多数网络分析工具)时意识到这种不准确性的讨论,另一个有用的链接是time_on_page_and_time_on_site_how_confident_are_you

只是想在 stackoverflow 上提出这个问题,因为我找不到类似的问题并开始对此进行讨论,但是我的解释是,确实没有办法解决这个问题,但最好意识到这一点。

有什么想法吗?

-------------------------------------------------- - - 更新 - - - - - - - - - - - - - - - - - - - - - - - --------

这是一个名为 Savio.no 的博客向我建议的另一个链接,这是一个好方法吗?

如何测量-true-time-with-google-analytics

I have been trying to research the hack proposed by Avinash Kaushik in his book Web Analytics 2.0. He poses the problem whereby most web analytics tools are unable to record the time a user spent on the last page they visit on a website, or on the only page they visit. In other words if user comes to page 1, a timestamp is created showing the time they arrived at the page, when they visit page 2, a second timestamp is created. The time spent on page 1 can be calculated by timestamp 2 - timestamp 1. However if the user closes the browser window or navigates away from the website there is no way to record time on page 2. Here is a link to this problem on Kaushik.net

standard-metrics-revisited-time-on-page-and-time-on-site

One proposed hack is to use the window.onbeforeunload event to call a method and push the time that the page was unloaded to google analytics. So I tried the following code -

window.onbeforeunload = capturePageExit;
function capturePageExit()
  {
    _gaq.push(['_trackPageview', '/page-exit?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer]);
    return("You are about to close this page");
  }

Using firebug I can see that the correct __utm.gif image is requested and the correct params are sent to google analytics. But clearly there is a problem now that this will be called on each page unload and so each visitor will appear to go from page1 -> page-exit -> page2 -> page-exit -> page3 -> page-exit... but I should get a more accurate time on site reading, right?

However this is at the expense of accurate navigation-summary data and so not a good solution. What would be good is if I could tell - if user has clicked the close browser/tab button or is navigating away from my site then record the page-exit.

I cant find a great deal of information about how to solve this problem, plenty of discussion about being aware of this inaccuracy when interpreting google analytics (and most web analytics tools probably), another useful link is time_on_page_and_time_on_site_how_confident_are_you

Just wanted to raise this on stackoverflow as I cant find a similar question and start a discussion about this, but my interpretation is that there isnt really a way around this problem but it is just better to be aware of it.

any thoughts?

------------------------------------------------------ UPDATE -----------------------------------------------------

Here is another link that was suggested to me from a blog called Savio.no, is this a good method?

how-to-measure-true-time-with-google-analytics

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

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

发布评论

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

评论(1

川水往事 2024-11-17 15:01:18

网络分析不是一门精确的科学。数据始终是近似值,并且大部分时间都是采样数据。

网络分析工具追求的是精度而不是准确性。 本白皮书介绍了原因在使用网络分析时,精确度更重要,而准确性则不太重要。

一旦您了解了精确度和准确度之间的区别及其重要性,您就会明白获得准确的现场时间指标并不重要,重要的是能够清楚地表达该指标的趋势或变化的精确测量。

换句话说,忘记绝对数字,学会使用趋势和变化来报告。

另一个建议是,如果你永远不会使用它,就不要费心调整 GA 来完美地渲染每个指标。关心您可以使用的指标。我所说的使用是指可行的分析

然而,在某些情况下,一些代码调整可以帮助您测量现场时间。一个明显的例子是博客。您可能想在博客中实现类似的功能,因为您的大多数访问都会查看您的主页,阅读您的帖子,然后离开,所有这些都是在同一个 PageView 中完成的,因此触发一个 PageView 可能是一个好主意当用户离开以获取网站上的正确时间时发生事件,或者当用户滚动超过某个阈值时触发事件,最终您将测量相同的事件,如果用户滚动更多,他会阅读更多内容,并且如果用户花费的时间比他阅读的内容更多。因此,跟踪这两个指标来衡量相同的效果可能没有意义。只需选择一个并坚持使用它,让它运行一段时间以创建历史数据,然后使用它。

Web Analytics is not an exact science. Data is always approximate and most of the time sampled.

Web Analytics tools strive for Precision not accuracy. This whitepaper describes why it's more important to have precision and less important to have accuracy when working with Web Analytics.

Once you understand the difference between precision and accuracy and why it matters you will understand that it's not important to get the exact time on site metric, but a precise measure that could clearly express trendings or changes to that metric.

On other words forget about absolute numbers, learn to report using trends and changes.

Another advice, don't bother tweaking GA to render every single metric perfectly if you're never gonna use it. Bother with metrics that you can use. And by use I mean Actionable analysis.

There are, however a few cases were some code tweaking can help you out measuring the time on site. A clear example is a weblog. You may want to implement something like that in a weblog, ince most of your visits will be looking at your homepage, reading your posts and then leaving, all that is done in the same single PageView so it may be a good idea to fire an event when the user leaves to get the correct time on site, or maybe fire an event when the user scrolls past some threshold, in the end you'll be measuring the same ting, if the user scrolls more he reads more, and if the user spends more time then he reads more. So it may not make sense to track those 2 metrics to measure the same effect. Just choose one and stick with it, leave it running for a while to create historical data and then make use of it.

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