测量网站在线时间
我想衡量用户在我的网站上花费了多少时间。社区网站需要它,您可以在其中说:“用户 X 已在此处花费了 1397 分钟。”
在阅读了一些有关这方面的文档后,我知道没有完美的方法来实现这一目标。你无法测量准确的时间。但我正在寻找一种能够提供良好近似值的方法。
你怎么能这么做?我的想法: 1) 每次页面浏览的在线时间计数器增加 30 秒。 2) 在每个页面视图上,保存当前时间戳。在下一个视图中,将保存的时间戳和当前时间戳之间的差异添加到在线时间计数器中。
如果这确实重要的话,我会使用 PHP 和 MySQL。
我希望你能帮助我。提前致谢!
I would like to measure how much time a user spends on my website. It's needed for a community site where you can say: "User X has been spending 1397 minutes here."
After reading some documents about this, I know that there is no perfect way to achieve this. You can't measure the exact time. But I'm looking for an approach which gives a good approximation.
How could you do this? My ideas:
1) Adding 30 seconds to the online time counter on every page view.
2) On every page view, save the current timestamp. On the next view, add the difference between the saved timestamp and the current timestamp to the online time counter.
I use PHP and MySQL if this does matter.
I hope you can help me. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这可能毫无意义......如果用户打开了三个选项卡并且在实际操作其他两个选项卡时“访问”您的网站怎么办?你想数一下吗?
This is probably pointless.... what if the user has three tabs open and is "visiting" your site while actually working on the other two tabs? Do you want to count that?
有两个因素对您不利 -
您只能收集时间点统计信息(页面浏览量),并且没有合理的方法来检测这些点之间发生的情况;
即便如此,您计算的还是浏览器窗口时间,而不是用户时间;用户可以轻松地同时在多个浏览器实例上打开多个选项卡。
我怀疑你最好的近似是分配每次点击的平均注意力时间,然后相乘。但你也可以衡量点击次数。
Two factors are working against you -
You can only collect point-in-time statistics (page views), and there's no reasonable way to detect what happened between those points;
Even then, you'd be counting browser window time, not user time; users can easily have multiple tabs open on multiple browser instances simultaneously.
I suspect your best approximation is attributing some average amount of attention time per click and then multiplying. But then you might just as well measure clicks.
为什么不直接衡量实际可以衡量的内容呢?:推荐、页面浏览量、点击率等。
收集和宣传这些类型的数字完全符合网络衡量标准的其他方面。
此外,如果有人打开一个网页,然后,比如说,去度两周的假期,那么如何最好地解释它呢?
Why not just measure what actually can be measured?: referrals, page views, click-throughs, etc.
Collecting and advertising these kinds of numbers is completely in line with the rest of the world of web metrics.
Besides—if someone were to bring up a web page and then, say, go on a two week holiday, how best to account for it?
您可以做的是检查用户是否在页面上处于活动状态,然后每隔 X 秒(60 秒可以吗?)向您的服务器发送一个 ajax 请求,以确定用户是否在页面上处于活动状态。
然后,您可以使用您提到的第二种方法来计算两个“活动”时间戳之间的时间差,这些时间戳之间的时间间隔不超过一两个间隔。添加这些将给出用户在您网站上花费的时间。
What you could do is check if a user is active on the page and then send an ajax request to your server every X seconds (would 60 secs be fine?) that a user is active or not on the page.
Then you can use the second method you have mentioned to calculate the time difference between two 'active' timestamps that are not separated by more than one or two intervals. Adding these would give the time spent by the user on your site.
Google Analytics(分析)包含一个非常强大的事件记录/跟踪机制,您可以可以定制并利用以获得对用户行为的真正良好的测量 - 我会研究一下
google analytics includes a very powerful event logging/tracking mechanism you can customize and tap into get really good measurements of user behavior - I'd look into that
一个非常简单的解决方案是使用隐藏的 iframe 定期加载 php 网页。加载的网页记录开始时间(如果不存在)和停止时间。当此人离开页面时,您会看到此人第一次访问该网站的时间以及他们最后一次访问该网站的时间。在本例中,时间戳每 3 秒更新一次。
我使用文件来保存日志信息。我使用的文件名由月-日-年 ipaddress.htm
示例 iframe php 代码组成。将其放入 yourwebsite/yourAnalyticsiFrameCode.php 中:
定期重新加载主网页中的 iframe 的 javascript:
主网页中的 iframe 如下所示:
显示时间戳文件的一种非常简单的方法:
您会得到如下结果页面:
22-Mar-2015 104.37.100.30
18:09:03 22-Mar-2015
19:18:53 22-Mar-2015
22-Mar-2015 142.162.20.133
18:10 :06 2015年3月22日
18:10:21 2015年3月22日
A very simple solution is to use a hidden iframe that loads a php web page periodically. The loaded web page logs the start time (if it doesn't exist) and the stop time. When the person leaves the page you are left with the time the person first came to the site and the last time they were there. In this case, the timestamp is updated every 3 seconds.
I use files to hold the log information. The filename I use consists of month-day-year ipaddress.htm
Example iframe php code. Put this in yourwebsite/yourAnalyticsiFrameCode.php:
The javascript to periodically reload the iframe in the main web page.:
The iframe in the main web page looks like this:
A very simple way to display the time stamp files:
You get a results page like this:
22-Mar-2015 104.37.100.30
18:09:03 22-Mar-2015
19:18:53 22-Mar-2015
22-Mar-2015 142.162.20.133
18:10:06 22-Mar-2015
18:10:21 22-Mar-2015
我认为客户端 JavaScript 分析就是这个问题的解决方案。
你有 google analitycs,piwik,还有 JS 中的商业工具也能做到这一点。
I think client side JavaScript analytics is the solution for this.
You have the google analitycs, piwik, and there also commercials tools in JS that do exactly that.