analytics icon indicating copy to clipboard operation
analytics copied to clipboard

Monthly time on page number is incorrect

Open soerenreinert opened this issue 1 year ago • 6 comments

Past Issues Searched

  • [X] I have searched open and closed issues to make sure that the bug has not yet been reported

Issue is a Bug Report

  • [X] This is a bug report and not a feature request, nor asking for self-hosted support

Using official Plausible Cloud hosting or self-hosting?

Plausible Cloud from plausible.io

Describe the bug

We have a page that has time on page values for only 3 days in July 2024 (44s, 1m41s, and 2m11s). However, for the monthly view of July 2024 the time on page in the dashboard shows 6m40s. Other pages have the same issue.

Expected behavior

The average time on page for July 2024 should be between 1-2mins, and can't be 6m40s.

Screenshots

For example July 2: Screenshot 2024-08-09 194003

Monthly view July 2024: Screenshot 2024-08-09 194015

Environment

- OS: Windows
- Browser: Chrome
- Browser Version: 127.0.6533.100

soerenreinert avatar Aug 09 '24 17:08 soerenreinert

Hi everyone, I would like to give a hand!

I'm taking a look at the code and I can't run the project on my machine, is there any docs with the instructions?

Thanks!

pmareke avatar Aug 25 '24 16:08 pmareke

👋 @pmareke

We have https://github.com/plausible/analytics/blob/master/CONTRIBUTING.md

ruslandoga avatar Aug 26 '24 02:08 ruslandoga

👋 @pmareke

We have https://github.com/plausible/analytics/blob/master/CONTRIBUTING.md

Ou thanks!!!

pmareke avatar Aug 26 '24 05:08 pmareke

Hi @soerenreinert after taking a look to the code, it looks like the Time on Page is not the average but the sum of all the time the users spent in a given page.

It makes sense then that you have 44 seconds in your page for one day and 6m40s in a month.

If some of the maintainers can confirm my hypothesis would be great!

pmareke avatar Aug 26 '24 07:08 pmareke

Right now "Time on Page" is neither an average nor a sum.

It's something like sum(duration(page)) / count(unique(page, next_page, session))

SELECT 
  pathname,
  sum(duration)/countIf(transition) -- <- time_on_page
FROM (
  SELECT
    pathname,
    next_pathname != pathname AS transition,
    sum(next_timestamp - timestamp) AS duration
  FROM (
    SELECT
      leadInFrame(timestamp) OVER event_horizon AS next_timestamp,
      leadInFrame(pathname) OVER event_horizon AS next_pathname,
      timestamp,
      pathname,
      session_id
    FROM events_v2 SAMPLE 20000000
    WHERE -- {...site and date range filter...}
    WINDOW event_horizon AS (
      PARTITION BY session_id
      ORDER BY timestamp
      ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING
    )
  )
  WHERE next_timestamp != 0 AND -- {...some page filter...}
  GROUP BY pathname, next_pathname, session_id
)
GROUP BY pathname

There are plans to improve it.

ruslandoga avatar Aug 26 '24 07:08 ruslandoga

Thanks for reporting this @soerenreinert! And thanks @pmareke for your investigation!

There are currently some known issues around the time_on_page metric, which we're planning to fix along with improving the tracking of the metric and making it more accurate in general.

@soerenreinert, I'll be happy to take a closer look at this with specific data if you could please reach out to us at [email protected] and let us know the name of your site in Plausible.

RobertJoonas avatar Aug 26 '24 08:08 RobertJoonas

I'll close this thread for now as it currently works as expected. the time on page issue itself has its own thread where we'll track and post the progress: https://github.com/plausible/analytics/issues/2161

metmarkosaric avatar Sep 10 '24 11:09 metmarkosaric