DEV Community

Discussion on: How to get time spent by users on a webpage using Node.js?

stefant123 profile image

Couldn't you just saved the time when the user opened the page in the cookie, and then when he leave the page, just calculate the difference between the time when he left, and the time when he opened the page? This way you will get the exact time spent on the site without the overhead that setInterval applies.

kalpitrathore profile image
Kalpit Rathore Author

Yeah, We can achieve it in this way also

Some comments have been hidden by the post's author - find out more