Usercase: I need to track the user's duration on the site. This is calculated as (end datetime - start datetime). This works fine if the user clicks signout. then the system can record the end datetime. But I am issue in the edge cases: User's session ends due to - loss of internet connection at user's end, browser closed, system went down, etc. In these cases how will the system know the end datetime so I can calculate the duration.Need the end datetime to be calculated as close as possible to the real datetime. If this is not possible then upto 5 mins of accurate is fine.
One possible way i see is the keep pinging the client system and check if active or not. But I dont want to do this as it adds unwanted bandwidth. So any other way to get this info for the edge cases?