I'm not sure
where on which Stack Exchange site to ask this question. I think this Stack Overflow is the wrong site, but I'm not sure where it should go. I see some specific answers that are related to more specific questions about various implementations of ajax calls or keepalive type behavior, but no discussion on alternate methods.
What methods exist to detect when a user has closed the browser? The only reliable method I know of is to ping the server with frequent ajax calls from the browser. The objective is to gain insight into whether the user is active in the browser to within about a minute.
Some details that may be useful (or maybe not):
- We keep session data in a mongo database.
- We have APIs we could send pings to.
- We have background workers.
Some Possible Ideas For Other Answers
I don't have enough information to create better suggestions than these.
- Maybe there could be a database trigger.
- Maybe there could be a background worker that looks at session data.
(Edited to ask speficially which Stack Exchange site I should post to.)