Determining Vis Length on Bounces


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?


(vipsoft) #2

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.

(vipsoft) #3

Ok, it’s now a single API method on the client: setHeartBeatTimer(initialDelay, recurringDelay)


Awesome! Will I need to wait until next release to take advantage? Or is there a nightly build I can install? Is it required?

Thanks again!

(vipsoft) #5

Better to wait for the release. Trunk is in flux.


Is this active in 1.2? And would this be the correct way to implement?

try {
var piwikTracker = Piwik.getTracker(pkBaseURL + “piwik.php”, 2); piwikTracker.trackPageView();
} catch( err ) {}

(Matthieu Aubry) #7

not active, it will be probably in 1.3


I have updated to v 1.3 but still have 0s visits on flash website. Is it any way in piwik 1.3 to switch on heartbeat if it’s not on by default ??

(Matthieu Aubry) #9

Not yet active, see Support Ping requests to report a better 'time on page' · Issue #2041 · matomo-org/matomo · GitHub