PhoenixKitWebAnalytics.Schemas.DailyStat (PhoenixKitWebAnalytics v0.5.0)

Copy Markdown View Source

One day of pre-aggregated totals per site — what survives after raw events are pruned.

PhoenixKitWebAnalytics.Retention writes one row per (date, site) for completed days, then deletes raw events past the retention window. Reports read raw events when they are still there and fall back to these rows for older days, so the long-range trend line outlives the raw data.

Adding days up

visitors is a distinct count for that day — and it does add up across days, because the visitor ID itself changes every day (see PhoenixKitWebAnalytics.Visitor): nobody can be the same visitor on two days, so the sum over a range is exactly what a distinct count over the raw events would give. That is what lets reports read finished days from here.

The per-day breakdowns (pages, referrers, …) are PhoenixKitWebAnalytics.Schemas.DailyDim rows.

site is "" (not NULL) when a hit had no host, so the unique index on (date, site) actually constrains those rows.

Summary

Functions

Average session length in seconds, or nil when the day recorded no sessions.

Bounce rate as a percentage, or nil when the day recorded no sessions.

Changeset for a daily rollup row.

Types

t()

@type t() :: %PhoenixKitWebAnalytics.Schemas.DailyStat{
  __meta__: term(),
  bounces: term(),
  date: term(),
  duration_count: term(),
  duration_ms_sum: term(),
  engaged_count: term(),
  engaged_ms_sum: term(),
  events: term(),
  exits: term(),
  inserted_at: term(),
  pageviews: term(),
  scroll_count: term(),
  scroll_sum: term(),
  sessions: term(),
  site: term(),
  total_session_seconds: term(),
  updated_at: term(),
  uuid: term(),
  visitors: term()
}

Functions

avg_session_seconds(daily_stat)

@spec avg_session_seconds(t()) :: float() | nil

Average session length in seconds, or nil when the day recorded no sessions.

bounce_rate(daily_stat)

@spec bounce_rate(t()) :: float() | nil

Bounce rate as a percentage, or nil when the day recorded no sessions.

changeset(stat, attrs)

@spec changeset(t(), map()) :: Ecto.Changeset.t()

Changeset for a daily rollup row.