Pixelex.Plug (Pixelex v0.1.0)

Copy Markdown View Source

Count page views from the server. No JavaScript, nothing to block.

# lib/my_app_web/endpoint.ex, after Plug.Static
plug Pixelex.Plug

Why this is the primary transport and the tracker is the optional one

Every hosted analytics product measures from the browser because it has no other choice — it is not running inside your application. A library is, so it can count the request itself. Nothing is on a filter list, nothing depends on JavaScript executing, and the record is already complete before the response is sent.

Plausible's own case study found a site losing 58% of visitors to ad-blockers with Google Analytics. That number is an upper bound on third-party scripts, and it is the number this plug does not have.

What it skips, and why

Anything that is not a person looking at a page: non-GET requests, non-HTML responses, non-2xx responses, and the ingest endpoint itself. Counting a stylesheet as a page view is the failure mode of naive request logging, and it is why "page views" from a request log never match anything.

Options

  • :site_id — a string, or a fun(conn). Defaults to the request host.
  • :skip — a fun(conn) returning true to ignore a request.
  • :paths — only count requests whose path starts with one of these.