Hi there,
I would like to help you out with this feature. There are ways in Jquery/Native javascript to add hooks and get callback when a user is closing a tab or entire browser, or even when user is navigating away from your website by entering a different url in that address bar manually.
Would be great if you can ping me for taking this further.
Cheers.