1

Can you tell me how django can be used to track the time a user spent on a page in milliseconds, for example?

X-Newbie
  • 13
  • 2
  • https://stackoverflow.com/questions/37794336/measure-time-a-user-stays-in-a-webpage-and-display-it-for-the-admin-python-dj Please check if this is what you are trying to achieve. – Jayaram18 May 24 '22 at 16:57
  • Does this answer your question? [Measure time a user stays in a webpage and display it for the admin (Python - Django)](https://stackoverflow.com/questions/37794336/measure-time-a-user-stays-in-a-webpage-and-display-it-for-the-admin-python-dj) – Stephen Ostermiller May 24 '22 at 19:36

1 Answers1

1

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.