Remix.run Logo
Hnrobert42 5 days ago

Could you send the beacon every five minutes? When the beacon stops coming in for 30 minutes assume that the tab closed or the user went off-line.

ivanjermakov 5 days ago | parent | next [-]

> every five minutes

This is tricky in JavaScript, because timers are asleep/throttled in inactive tabs: https://developer.mozilla.org/en-US/docs/Web/API/Window/setT...

And if onbeforeleave analytics is not evil, doing stuff in inactive tabs is certainly is.

hoppp 5 days ago | parent | prev [-]

You could just have a websocket open then. But its unreliable because if the user's internet cuts out maybe they still on the tab, so watching websocket disconnect is not perfect either