I was recently reading that there was a way to get the visit length of a visitor bounced by calling a javascript function on an action such as “onClose” that updates the visit length in the database. Is there support for this with Piwik or a way for me to implement it?
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.