Shared period/site filter handling for the report LiveViews.
Every report page answers the same two questions — when and which site —
and keeps both in the URL so a filtered view can be bookmarked, shared, and
survives a refresh. A third, optional path narrows every report to one page
(set by clicking a path on the Pages report). This module owns that plumbing so the five pages don't
each reimplement it.
Two switches widen what is counted: flagged shows the traffic the
settings leave out (the site's own people and networks — see
PhoenixKitWebAnalytics.TrafficFlags), bots shows bot traffic. Either
one reads the period from raw events.
Summary
Functions
Reads period, site, path, flagged and bots from the URL params
and assigns :filter, :period, :site, :path, :sites, and
:bucket.
Applies the current filter's params to another report path.
How many people are on the site now: the larger of the pages open over a
LiveView socket (exact) and the visitors with a hit in the last five minutes
(covers pages without a LiveView). Traffic flagged with a bit of
excluded_flags (the settings' mask by default) isn't counted.
Builds the URL to patch to when the filter form changes.
Whether the filter reads its whole period from raw events because it
counts in traffic the rollups don't hold — bots, or a TrafficFlags bit
(by the report's switch or a setting).
Re-reads the online count for the page's current site filter.
The current filter as URL params, for links between report pages that should keep the selected window.
Assigns :online and, once connected, refreshes it every 30 seconds by
sending the LiveView :refresh_online — which it hands back to
refresh_online/1. Every report page shows the same badge this way.
Functions
@spec assign_filter(Phoenix.LiveView.Socket.t(), map()) :: Phoenix.LiveView.Socket.t()
Reads period, site, path, flagged and bots from the URL params
and assigns :filter, :period, :site, :path, :sites, and
:bucket.
Unknown period values fall back to the default rather than erroring — these come from a URL anyone can edit.
@spec link_to(String.t(), PhoenixKitWebAnalytics.Reports.filter()) :: String.t()
Applies the current filter's params to another report path.
@spec online(String.t() | nil, non_neg_integer() | nil) :: non_neg_integer()
How many people are on the site now: the larger of the pages open over a
LiveView socket (exact) and the visitors with a hit in the last five minutes
(covers pages without a LiveView). Traffic flagged with a bit of
excluded_flags (the settings' mask by default) isn't counted.
Builds the URL to patch to when the filter form changes.
Empty values are dropped, so the default view has a clean URL.
@spec raw?(PhoenixKitWebAnalytics.Reports.filter()) :: boolean()
Whether the filter reads its whole period from raw events because it
counts in traffic the rollups don't hold — bots, or a TrafficFlags bit
(by the report's switch or a setting).
@spec refresh_online(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t()
Re-reads the online count for the page's current site filter.
@spec to_params(PhoenixKitWebAnalytics.Reports.filter()) :: map()
The current filter as URL params, for links between report pages that should keep the selected window.
@spec track_online(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t()
Assigns :online and, once connected, refreshes it every 30 seconds by
sending the LiveView :refresh_online — which it hands back to
refresh_online/1. Every report page shows the same badge this way.