Looking at the source, avg_time_on_site is calculated from time_to_next_event, filtered to exclude values greater than 30 minutes or NULL. This means the last event in a session (where time_to_next_event is NULL) is excluded from the average.
The tracker script also doesn't seem to send any outgoing events (sendBeacon, visibilitychange, pagehide, etc.), so we were wondering: is the time spent on the last visited page intentionally not considered in the avg time calculation?
We tested sending a custom event via the API:
POST /api/event
{ "name": "heartbeat", "entity_id": "...", "url": "..." }
This gets recorded and correctly populates time_to_next_event on the previous event. We could use setInterval with the exported event() function as a workaround.
Two questions:
- Is there a recommended way to capture time on the last page of a session?
- Do custom event names like
"heartbeat" affect the hits count in the dashboard, or are only "pageview" events counted?
Thanks!
Looking at the source,
avg_time_on_siteis calculated fromtime_to_next_event, filtered to exclude values greater than 30 minutes orNULL. This means the last event in a session (wheretime_to_next_eventisNULL) is excluded from the average.The tracker script also doesn't seem to send any outgoing events (
sendBeacon,visibilitychange,pagehide, etc.), so we were wondering: is the time spent on the last visited page intentionally not considered in the avg time calculation?We tested sending a custom event via the API:
This gets recorded and correctly populates
time_to_next_eventon the previous event. We could usesetIntervalwith the exportedevent()function as a workaround.Two questions:
"heartbeat"affect the hits count in the dashboard, or are only"pageview"events counted?Thanks!