matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.7k stars 2.62k forks source link

time on page in the popup #20214

Closed matomoto closed 11 months ago

matomoto commented 1 year ago

Matomo Version: 4.13.0 Matomo Update History: 4.11.0,4.10.1,4.9.1,4.7.0,4.6.2,4.6.1 Matomo Install Version: Unknown - pre 3.8. Latest Available Version: 4.13.0

I have seen a mistake by the "Time on page" popup in the real-time page by the last visit page, when the time on page is under 30 seconds (i think). I have a own 1 seconds heartbeat (ping) for the first 10 seconds and a matomo heartbeat with 10 seconds. The matomo script starts after a timeout of 1 second (prevent tracking of 0 seconds viewer).

Here by a visitor, there leave the page after visit 10 pages. Time in first page popup: 21:10:52 Time in last page popup: 21:12:06 = 1:16 Last time: 21:12:06 Time on page: (1min 16s) In the popup by the last page: 0s matomo-time-on-page-x-actions

Here by a visitor, there leave the page after visit it. The Time on page is 10 seconds, but in the popup 0 seconds. matomo-time-on-page-1-action

By another viewer with more than 30 seconds time on page in the last page is the "Time on page" greater than 30 seconds. I think for the calculation of the time on page in the popup there is a 30 seconds barrier?

Edit: A better example.

2 actions Time on page: (1 min 16 sec) Time in first page popup (below): 21:30:48 Time in last page popup (above): 21:32:00 = 1:12 The viewer was also 4 seconds on the last page. matomo-time-on-page-2-action

By another 1 action viewer with time on page 13 seconds, there was 13 seconds in the popup. It is also not on all time a mistake/bug or a calc time barrier. Its difficult.

Edit 2: Its possible not a 30 seconds barrier, rather 10 seconds, but it seems its not barrier, rather the firered pings in the first 10 seconds with a setInterval are ignored in the popup time on page calc and only the matomo heartbeat (10 seconds) are in use of the time calculation in this case. But also this is not really the cause. Its difficult.

bx80 commented 1 year ago

Thanks for the feedback @matomoto,

From my understanding of https://developer.matomo.org/guides/tracking-javascript-guide#accurately-measure-the-time-spent-on-each-page a heartbeat timer of 10 seconds, eg. _paq.push(['enableHeartBeatTimer', 30]); would mean that only visits of 10 seconds or more on the last page of the visit would record a non-zero "time on page" value.

Does this behaviour change for you with a lower heartbeat timer value?

matomoto commented 1 year ago

Hello bx80,

i have a very custom matomo tracking code with own settings. For example, the matomo script is loaded first after 1 second timeout with a setTimeout. This prevents the tracking of 0 seconds views. It is to prevent littering my matomo database. The next is a own heartbeat with a setInterval for the first 11 seconds each second, also with a clearInterval.

var myheartbeat = setInterval(function() {
  _paq.push(['ping']);
}, 1000);
setTimeout(function() {
  clearInterval(myheartbeat);
}, 11000);

With this tracking code i see the time on page in the first 10 seconds (except the first second) more detailed as default. I see also 1 or 2 ... 9 ... 10 second/s time on page values.

Then i have a regular _paq.push(['enableHeartBeatTimer', 10]);.

With a

window.addEventListener('beforeunload', function(e) {
  _paq.push(['ping']);
});

i see also more detailed time on page after 10 seconds.

I have observed, that the "Time on page" in the popup is <11 = 0, like a:

var time_on_page = get_time_on_page();
if (time_on_page < 11) {
  time_on_page = 0;
}
heurteph-ei commented 1 year ago

Looking the screenshots, it seems just the last page duration is not taken into account. In @matomoto first example, the last page time seems to be 2 seconds, but is displayed 0 (21:12:06 - 21:10:52 = 00:01:14) because total visit duration is 00:01:16 In the second example, 21:32:00 - 21:30:48 = 00:01:12. Then the last page duration is 4s. Maybe the page calculation is set only when another page comes after? But the visit duration is well calculated... 🤔

matomoto commented 1 year ago

Looking the screenshots, it seems just the last page duration is not taken into account. Maybe the page calculation is set only when another page comes after?

Not really.
The "Time on Page" in the black popup is "0 seconds", when the Time on page is <11 seconds.

Example: I have by visits with 0 actions and a regular "Time on Page" = 10 seconds a "Time on Page" in the black popup with "0 seconds". With regular 11 seconds, in the popup also 11 seconds. All lower than 11 seconds is 0 seconds in the black popup. That is the situation i observed.

The problem: I don't see, how much time on page is in the last page, when it is lower than 11 seconds. By 0 actions, is see the time on page in the regular box - here it is not a problem. By many pages in one visit i must self calculated the time on page for the last page, when it is lower than 11 seconds.

heurteph-ei commented 1 year ago

The problem: I don't see, how much time on page is in the last page, when it is lower than 11 seconds.

Maybe in this case this is the difference between Visit duration and time between last and first page... In case of last page duration > 10 seconds, my operation (VD - (TLP - TFP)) true or false?

matomoto commented 1 year ago

Hello heurteph-ei, is this a question to me?

The Time on Page calculation in the last page is OK by greater than 10 seconds. My question is: is there a time barrier in the calculation that makes <10 = 0 ? Because that is the fact i observed.

heurteph-ei commented 1 year ago

@matomoto, yes the question was for you 😉 Then is seems the total visit duration is well calculated any time, but the last page duration is not set when < 10... How are configured default_time_one_page_visit? (not sure it could impact your problem...)

matomoto commented 1 year ago

global.ini.php

default_time_one_page_visit = 0

untoched. And i don't touch it, because it manipulates the real Time on page. Consider myheartbeat above.

MatomoForumNotifications commented 1 year ago

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/0-sekunden-aufenthaltsdauer-pro-url/49486/2

sgiehl commented 11 months ago

After checking this one again, I think it's actually a duplicate of https://github.com/matomo-org/matomo/issues/9539 The time on page for the last page currently isn't set correctly even when using a heatbeat timer.