如何计算用户在网站上花费的时间?

发布于 2025-01-31 19:56:54 字数 42 浏览 2 评论 0原文

您能告诉我如何使用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 技术交流群。

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

发布评论

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

评论(1

千柳 2025-02-07 19:56:54

一种方法是使您的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.

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