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.
Summary
Functions
Reads period, site and path 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).
Builds the URL to patch to when the filter form changes.
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 and path 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()
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).
Builds the URL to patch to when the filter form changes.
Empty values are dropped, so the default view has a clean URL.
@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.