PhoenixKitWebAnalytics.Schemas.DailyStat (PhoenixKitWebAnalytics v0.2.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.

Why only totals

visitors is a distinct count for that day, and distinct counts don't add up: summing two days of visitors overstates the real number whenever someone visited on both days. Treat these columns as per-day facts, never as something to sum across rows. Per-dimension breakdowns (top pages, referrers, …) are only ever computed from raw events — once a day is pruned, its breakdowns are gone by design.

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(),
  events: term(),
  inserted_at: term(),
  pageviews: 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.