Is there a way to tell if a user on my website has left (i.e. connection dropped, navigated away etc.) in real time?
I am building a RoR website and want to initiate an event as soon as a user leaves my site for whatever reason (e.g. connection, navigating away from domain etc.)
Thanks in advance for any help.
No, there isn’t.
The best you can do is send an AJAX request every X seconds (perhaps only if the user moves the mouse). If the server doesn’t receive any requests for 2X seconds, assume that the user left.