PhoenixKitWebAnalytics. Web. TrackController
(PhoenixKitWebAnalytics v0.5.0)
Copy Markdown
View Source
Two optional client-side entry points, for the cases the plug can't see.
Neither is needed for ordinary server-rendered traffic — that's
PhoenixKitWebAnalytics.Plug, which needs no client cooperation at all.
Both are off by default: page views need web_analytics_beacon_enabled;
named custom events are accepted with it or web_analytics_client_script
on; the client script's clicks, scroll and exits need the latter.
POST /phoenix-kit/analytics/event— custom events ("signup","add_to_cart") reported bywindow.phoenixKitAnalytics(name, props), from the<.beacon />snippet or the optional client script; and the client script's clicks, scroll depth and page exits. Page views and custom events needweb_analytics_beacon_enabled; the client script's hits needweb_analytics_client_script.GET /phoenix-kit/analytics/pixel.gif— a 1×1 GIF for pages the plug never runs for: full-page CDN caches, statically exported pages, AMP.GET/POST /phoenix-kit/analytics/recording— session recordings: whether to record this visitor on this page, and the recorded chunks. Off unlessweb_analytics_recordingis on; seePhoenixKitWebAnalytics.Recordings.
Trust boundary
These endpoints are public and unauthenticated. What a payload can and cannot
influence is enforced in PhoenixKitWebAnalytics.Web.BeaconPayload.
Beyond that: anyone can POST here and inflate counts, exactly as with every client-side analytics product. Leave the beacon off unless you need custom events, and put per-IP rate limiting in front of it if you do.
Both actions answer the same way whether or not the beacon is enabled — a disabled beacon is not an error the page should surface, and the response tells a caller nothing about the site's configuration.
Summary
Functions
Records a hit reported by the beacon or the client script.
Records a page view and returns a 1×1 GIF.
Stores a chunk of a session recording.
Whether the client script should record this page: {"record": true} or
false. Private and short-lived in caches — the answer depends on the
visitor (sampling) and on a setting that can change.
Functions
@spec event(Plug.Conn.t(), map()) :: Plug.Conn.t()
Records a hit reported by the beacon or the client script.
@spec pixel(Plug.Conn.t(), map()) :: Plug.Conn.t()
Records a page view and returns a 1×1 GIF.
@spec recording(Plug.Conn.t(), map()) :: Plug.Conn.t()
Stores a chunk of a session recording.
@spec recording_config(Plug.Conn.t(), map()) :: Plug.Conn.t()
Whether the client script should record this page: {"record": true} or
false. Private and short-lived in caches — the answer depends on the
visitor (sampling) and on a setting that can change.