admin管理员组文章数量:1327119
I like to measure the time a user spent on a particualr page of my webapp. First i thought about catching the onunload/onbeforeunload event in the browser and notify the server via a XMLHttpRequest that the user is leaving now like:
<body onunload="userLeaves('/url/to/current/page',xxx);" ...> ... </body>
where xxx is the inital tiemstamp when the page was rendered.
Unfortunately this solution doesnt work in all browser (e.g. Opera). So my second idea was to ping the server constantly. To calculate the visiting time someone has to take the last ping time and subtract it from the inital timestamp. But i dont think thats a good solution either especially when a user has opend 3 or 5 tabs and every tab is firing events every 500 ms ...
how would you measure the visiting time? has someone a better idea to obtain the time spent on one particualr page?
I like to measure the time a user spent on a particualr page of my webapp. First i thought about catching the onunload/onbeforeunload event in the browser and notify the server via a XMLHttpRequest that the user is leaving now like:
<body onunload="userLeaves('/url/to/current/page',xxx);" ...> ... </body>
where xxx is the inital tiemstamp when the page was rendered.
Unfortunately this solution doesnt work in all browser (e.g. Opera). So my second idea was to ping the server constantly. To calculate the visiting time someone has to take the last ping time and subtract it from the inital timestamp. But i dont think thats a good solution either especially when a user has opend 3 or 5 tabs and every tab is firing events every 500 ms ...
how would you measure the visiting time? has someone a better idea to obtain the time spent on one particualr page?
Share Improve this question edited Aug 24, 2009 at 16:40 BigBlondeViking 3,9631 gold badge33 silver badges28 bronze badges asked Aug 24, 2009 at 16:24 ChrisChris 15.7k19 gold badges73 silver badges74 bronze badges 1- how did you end up doing? I'm also thinking about pinging the server – brauliobo Commented Jul 16, 2015 at 14:11
4 Answers
Reset to default 3The approach used by such tools as Google Analytics is that visit time is measured as the time the user hit the first page to the time they hit the last page within a single "visit". A single visit is defined as a series of page views by one user (cookie) where each visit is sufficiently close to the previous in time. I don't know what that limit is however.
In my experience, these kinds of tricks with unload events and so forth are bordering on being intrusive and users don't appreciate them. As such they add little to no value over a more passive approach like constructing a visit from cookies plus page view data.
I suggest almost any web analytic package depending on some of your business goals.
- Google Analytics: (free)
- Yahoo Analytics: (free)(beta)
- Woopra: (free)(beta)
- Omniture: ( expensive )(most feature rich, difficult learning curve )
[ there are others, some more tailored to Ad Network Reporting...]
Why not take a look at Google Analytics the standard tracking will capture these stats for you.
http://www.google./analytics/
It depends on how much error you would allow. If the error is in the order of tens of minutes, you only need a visit log, and set the session timeout interval for the last page. If you allow only hundreds of milliseconds, you will need to ping. If the error is anywhere in between, you still need to ping, albeit at a lower rate; or accept the fact that for a user who shut down the browser will not fire the onunload event.
本文标签: javascriptHow to measure visiting time of a userStack Overflow
版权声明:本文标题:javascript - How to measure visiting time of a user - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742201206a2431992.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论