Skip to content

Fix the three PostHog installation health warnings - #23

Merged
msmfa merged 2 commits into
masterfrom
analytics-health
Sep 11, 2026
Merged

Fix the three PostHog installation health warnings#23
msmfa merged 2 commits into
masterfrom
analytics-health

Conversation

@msmfa

@msmfa msmfa commented Sep 11, 2026

Copy link
Copy Markdown
Owner

PostHog's installation health check for the JavaScript in 30 Words project reported 3 of 6 checks passing. This fixes all three failures.

Reproduced first on the live site: only one POST https://eu.i.posthog.com/e/ per visit, with capture_pageleave: false and capture_performance: false in the live posthog.config.

$pageleave missing

Bounce rate and session duration could not distinguish a bounce from a long read. capture_pageleave is now on and the event passes the sanitizer. Verified against the real posthog-js on the live page: the event fires on navigation and survives sanitizing with a stripped $current_url.

Core Web Vitals not measured

LCP, CLS, FCP and INP are now captured and their numeric readings pass the sanitizer. The matching $web_vitals_<metric>_event objects carry attribution detail, including the DOM element behind each measurement, and are kept out two ways: the attribution bundle is switched off, and the sanitizer's existing scalars-only rule drops them regardless.

No reverse proxy

Requests went straight to eu.i.posthog.com, which tracking-protection lists match on by hostname. Both the library and ingestion now go through /e30 on the site's own origin, proxied by netlify.toml. The host comes from window.location.origin, so each production hostname stays same-origin instead of pointing at one canonical domain. Nothing loads from the PostHog domains any more, so they come out of the CSP and 'self' covers them.

A stale redirect would silently 404 every event, so the build now checks netlify.toml against the configured proxy path and region and fails if they drift. Confirmed the guard fires on a deliberately broken rule.

The sitemap lastmod commit is unrelated pre-existing work that was sitting uncommitted in the tree; it is split into its own commit.

npm test: 73 passing.

To verify on the deploy preview

  • GET /e30/static/array.js returns the PostHog library
  • GET /e30/array/<token>/config.js returns the remote config

Every sitemap URL now carries a `lastmod`. The date comes from the last
commit that touched `src/data.js` rather than from the build clock, so a
rebuild that changes nothing does not tell crawlers the whole site was
updated. Outside a git checkout the build falls back to today's date.
PostHog's installation health check flagged three gaps in how the site
reports. All three are fixed here.

Bounce rate and session duration were unreliable because the site never
sent `$pageleave`, so PostHog could not tell a one-page visit from a long
read. Turn `capture_pageleave` on and let the event through the sanitizer.

Core Web Vitals were not measured at all. Turn on web vitals capture for
LCP, CLS, FCP and INP, and allow their numeric readings through. The
matching `$web_vitals_<metric>_event` objects carry attribution detail,
including the DOM element behind each measurement, and stay out: the
attribution bundle is switched off and the sanitizer's existing rule that
only scalars pass keeps them from being sent even if that changes.

Requests went straight to `eu.i.posthog.com`, which tracking-protection
lists match on by hostname, so an unknown share of visits never arrived.
Route both the library and ingestion through `/e30` on the site's own
origin, proxied to PostHog by netlify.toml. The path is derived from
`window.location.origin` so each production hostname stays same-origin
rather than pointing at one canonical domain. Because nothing now loads
from the PostHog domains, they come out of the CSP and `'self'` covers
them.

A stale redirect would silently 404 every event, so the build checks
netlify.toml against the configured proxy path and region and fails if
they have drifted.
@msmfa
msmfa merged commit 8a802fb into master Sep 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant