onClose is not widely supported. There’s an onUnload and onBeforeUnLoad but neither are triggered if the user closes the tab or window.
Currently, there are two proposals.
- a ping is sent once, ‘n’ milliseconds after the init page view is logged; a reasonable value might be 30 seconds
- a heartbeat is basically a recurring ping, telling the server that the page is still open (though it may not necessarily have focus); a reasonable value might be 10 seconds
Either could be used to improve the bounce rate and visit length where only a single page is viewed during a visit. I have prototyped both on the client side (piwik.js), but haven’t made the necessary server-side changes yet.