I have been brainstorming ways to track how long a user stays on a page within my ASP.NET application. In order to do this, I am saving the userid, pagename, pageenteredtime, and pagelefttime in a database. Each entry also has its own unique identifier known as featureuselogid.
Currently, I can monitor when a user accesses the page using the page_load function on the server side. This allows me to save the userid, pagename, and pageenteredtime.
However, I am facing a challenge in determining the user's departure time from the page. I am aware of the window.onbeforeunload function in JavaScript that can handle various scenarios such as browser shutdowns and navigation away from the page.
The question now is, how can I pass the featureuselogid to JavaScript? If I'm able to achieve this, I believe I can utilize a webservice call from JavaScript to update the record with the pagelefttime.
Do you think this approach is misguided? Any advice would be greatly appreciated.