Currently, when the heart beat timer is enabled, we ping every 15s the Matomo server. If you have 1000 visitors on your page that makes 66req/s. It also sends a request every time you focus the window after you were on another tab.
This PR implements pretty much the opposite behaviour:
This means instead of possibly sending heaps of requests every few seconds we typically would maybe send one or two ping requests per pageview. Most of the times it be one (on page unload) or even none (when user was only a few seconds on a page).
Behaviour is otherwise the same, it's just more efficient by not sending as many requests. Instead we only send requests when needed. Which is either when the user is leaving the window, or closes the window.
First of all I appreciate this very effective change!
But did you consider Single Page Applications? Blur or unload may never happen in these cases. What I see currently:
Maybe you can ping on hashchange event or even better: provide a method to force ping. This would be helpful for matomo integrations in different frameworks or if we have own (custom)events that we are listening to.
@ZupZ3r0 AFAIK this should still work because all it does is update the overall visit time but not anything else.
@ZupZ3r0 btw there is also a tracker method named
@tsteur apperently it doesn't work out of the box, because the heartbeat sends only the first ping on pageload but never again (or only if you leave the active tab). This doesn't really break something, but results in a visit time of 1s for every action/event.
Anyway thanks for the hint with
_paq.push(['ping']), thats what I was looking for and helps in this situation :-)
@ZupZ3r0 be great to let me know if using
ping changes anything for you. Technically it shouldn't change anything from my understanding because no action/event will be updated in a ping request. Be great to give it a try though.
I have been testing for a few days now with sending a ping (
_paq.push(['ping'])) but I don't notice any difference in Avg Time on Page measurements.