Web Analytics 0.5.0: Real visitor addresses behind a proxy and ad clicks counted as paid
Web Analytics 0.5.0 fixes sites behind a reverse proxy, where every visitor looked like the proxy, and records auto-tagged ad clicks as paid traffic with their click identifier. Version 0.4.0 was never published, so its changes arrive with this release.
Visitors behind a reverse proxy
Behind a proxy, every visitor used to hash to the proxy’s address: people were merged into one visitor, and that visitor was often flagged as a bot for too many page views. The tracking plug, the beacon and the LiveView hook now read the address the way PhoenixKit core does. When the request comes from a private or loopback address, they take the last X-Forwarded-For entry, the one the proxy added, then X-Real-IP. A port the proxy appends is dropped. A request from a public address is the visitor, and its forwarded headers are ignored. The trust_x_forwarded_for setting no longer does anything, and true logs a warning once at start.
Settings warn when LiveView visits from a private address are not recorded because the socket’s connect_info lacks :x_headers.
Ad clicks are paid traffic
Ad clicks auto-tagged with gclid, gbraid, wbraid, msclkid, fbclid, ttclid or li_fat_id used to be recorded as direct, so the Acquisition report showed no paid traffic. The first identifier on the landing URL is now kept with its name, ready to report a conversion back to the ad platform. A visit with one is filed under the paid channel, with the platform as its source. fbclid is the exception: Meta adds it to ordinary clicks too, so it never overrides the referrer. A campaign parameter that isn’t valid UTF-8 no longer loses the hit.
Upgrading
Add :x_headers to the LiveView socket’s connect_info on both transports before you deploy: connect_info: [:peer_data, :x_headers, :user_agent, session: @session_options]. Without it, LiveView visits through a proxy or in local development are not recorded. Your proxy must set or append X-Forwarded-For itself; one that only sets X-Real-IP lets visitors name any address. Behind a CDN, add a RemoteIp plug before the tracking plug. Then run mix phoenix_kit.update for migration V07; on a large events table, build its indexes concurrently first, as the migration docs show. Expect more visitors and fewer bots from the deploy on; older visits are not recounted.
Full release notes: Web Analytics 0.5.0
0.5.0 · 7 October 2026
⚠️ Upgrade
- Add
:x_headersto the LiveView socket’sconnect_infofirst, then deploy — on both transports:connect_info: [:peer_data, :x_headers, :user_agent, session: @session_options]. Without it, a socket whose peer is a private or loopback address — a reverse proxy, a container network, a LAN,localhostin development — can no longer name its visitor, and the hook records nothing for it (no live navigation, interaction or “Right now” entry) instead of recording the peer as the visitor. Settings warns while that happens, and the “no JavaScript” bot check pauses while such skips are at least 5 % of a node’s live visits in the last 24 hours. The skip count lives in memory, so after a restart the node that runs the check leaves alone every visit that started before it had been up for 30 minutes. X-Forwarded-Forfrom a private or loopback peer is now trusted with no configuration, and its LAST entry is taken — the one the proxy appended, as PhoenixKit core reads it for a login;X-Real-IPonly when there is no readableX-Forwarded-For. Before, the FIRST entry was read, and only withtrust_x_forwarded_for: true. The proxy must therefore set or appendX-Forwarded-Foritself: one that only setsX-Real-IP(nginx with justproxy_set_header X-Real-IP) passes a visitor’s own header through, and the visitor can name any address. The same holds on an intranet where visitors have private addresses and reach the app directly.- Had
trust_x_forwarded_for: truebehind a CDN or a proxy with a public address (a CDN in front of the origin)? Add aRemoteIpplug (remote_ip) beforePhoenixKitWebAnalytics.Plug: a public peer’s headers are ignored now, so without it every visitor is one of the CDN’s addresses. Behind a chain (a CDN in front of a load balancer) the last entry is the CDN’s, soRemoteIpis needed there as well. - LiveView behind a CDN and a load balancer:
RemoteIpfixes the plug but not the socket, which reads:x_headersby the rule above and sees the CDN’s edge. Page load and live connection then hash to different visitors, and every LiveView visit is flagged a “no JavaScript” bot after 30 minutes. On such a site switch Spot bots by behaviour off (web_analytics_detect_bots). Withtrust_x_forwarded_for: trueand:x_headers, 0.4.0 read the first entry for both and didn’t have this problem. - Expect more visitors and fewer bots from the day of the deploy. Behind a
proxy every visitor used to hash to the proxy’s address: visitors sharing a
browser were merged into one, and the merged “visitor” was often flagged
rate(too many page views a minute). Visits recorded before the deploy are not recounted.
Fixed
- Behind a reverse proxy every visitor was the proxy. The plug, the beacon
and the LiveView hook read the client address by core’s rule
(
PhoenixKit.Utils.IpAddress.client_address/1/client_address_from_socket/1, whose answer is taken for a public peer): behind a private or loopback peer, the lastX-Forwarded-Forentry across all its lines, thenX-Real-IP. The headers are read by the module itself there, because a core that can’t parse a port (2.55 and earlier) passes over such anX-Forwarded-Forand answers withX-Real-IP, which a visitor can send. A port the proxy appended is dropped froma.b.c.d:portand[v6]:port(Caddy’s{remote}); a bare IPv6 address is never cut (2001:db8::1:443is an address).::ffff:a.b.c.dis read as IPv4. A public peer is the visitor and its forwarded headers are ignored.
Changed
- The
connect_infosnippets (README, Settings,LiveHookdocs) list:x_headers. The README has a “Behind a reverse proxy” section, including the proxy-side fix for Caddy ({remote_host}, or noheader_upat all).
Deprecated
config :phoenix_kit_web_analytics, trust_x_forwarded_for:has no effect.trueis warned about once as the module starts;falseis ignored.
Web Analytics 0.5.0. Install or update: {:phoenix_kit_web_analytics, "~> 0.5"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.