Skip to content

Avg Time on Site: how is the last page visit handled? #38

@marcochiodo

Description

@marcochiodo

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:

  1. Is there a recommended way to capture time on the last page of a session?
  2. Do custom event names like "heartbeat" affect the hits count in the dashboard, or are only "pageview" events counted?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions