如何计算用户在网站上花费的时间?
您能告诉我如何使用Django来跟踪用户在毫秒毫秒的页面上花费的时间?
Can you tell me how django can be used to track the time a user spent on a page in milliseconds, for example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使您的JavaScript记下页面加载的时间以及页面卸载的时间(使用
window.onbeforeunload
),然后将此数据发送到您的Django后端。然后,您的后端可以计算页面上花费的时间。或者,您可以使用Ajax调用每5秒钟的Ajax调用服务器进行良好的旧方法,以使您的前端/客户端进行轮询您的服务器,以便您知道,只要您收到请求,用户就已经至少花费了。
One way could be to make your Javascript note down the time when the page loads and also the time when the page unloads(using
window.onbeforeunload
) and then send this data to your Django backend. Then your backend can calculate the time spent on the page.Or you can go with the good old method of making your frontend/client poll your server using ajax calls say every 5 seconds so that you will know that the user has spent atleast as long as you got the requests.