@tsteur opened this Pull Request on October 25th 2019 Member

fix https://github.com/matomo-org/matomo/issues/15049

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:

  • Ping only on window blur (never on focus)
  • On window blur send only a request if the user was on the page for at least 15 seconds (or whatever is configured as heart beat timeout). Otherwise user maybe was just quickly switching between tabs but not actively on the page
  • Ping on unload of browser window but only when user was on page > 15 seconds (or configured heart beat timeout)
  • Stop sending ping requests 30 minutes after the first request (as it would not have any effect anyway)
  • Now requiring at least 5 seconds to be configured as heart beat timer as every second be quite extreme and we want to prevent this.

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.

@ZupZ3r0 commented on June 26th 2020

Hi,
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:

  • open the page initially: heartbeat ping gets fired when the page loses focus (I go to another tab or whatever) -> this works as described here and expected
  • but any pagechanges inside this app (via its navigation) does not trigger pings

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.

@tsteur commented on June 26th 2020 Member

@ZupZ3r0 AFAIK this should still work because all it does is update the overall visit time but not anything else.

@tsteur commented on June 27th 2020 Member

@ZupZ3r0 btw there is also a tracker method named _paq.push(['ping'])

@ZupZ3r0 commented on June 29th 2020

@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 :-)

@tsteur commented on June 29th 2020 Member

@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.

@miiimooo commented on October 3rd 2022

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.

This Pull Request was closed on November 5th 2019
Powered by GitHub Issue Mirror