plausible / docs

Documentation for Plausible Analytics
https://plausible.io/docs
Creative Commons Attribution Share Alike 4.0 International
212 stars 194 forks source link

Average visit duration when queried per page reported via API differs from one in UI #379

Closed huksley closed 1 year ago

huksley commented 1 year ago

Hi, I am using cloud version and query API using /aggregate API call, e.g.

const period = "month";
const id = "z-WeukB91Zws";
const stats = await fetch("https://plausible.io/api/v1/stats/aggregate?" +
  new URLSearchParams({
    site_id,
    period,
    filters: "event:page==/v/" + id,
    metrics: "visitors,pageviews,bounce_rate,visit_duration,events",
  }),
  {
    headers: {
      Authorization: `Bearer ${plausibleKey}`,
    },
  }
)
  .then(okstatus)
  .then((res) => res.json());
console.info(stats);

Output result is

{
  results: {
    bounce_rate: { value: 0 },
    events: { value: 136 },
    pageviews: { value: 7 },
    visit_duration: { value: 2086 },
    visitors: { value: 4 }
  }
}

Documentation states, visit_duration is in seconds, so it it 34 minutes?!

But in the UI it is more realistic (3m 48s)

image

My goal is to get statistics per /v/ID page on visits and custom goal execution (AddComment, Like, etc.). Is the API can be used for that?

metmarkosaric commented 1 year ago

thanks for reporting @huksley! we actually don't have time on page in the stats api at this time. what you're looking at is visit duration which is a different metric from time on page. we'd like to introduce time on page in the stats api in the future. there's a thread for this feature request here: https://github.com/plausible/analytics/discussions/2727. i'm closing this as we keep the github issues for actual changes to our docs. thanks!