Skip to content

feat: sanitized manual $pageview for PostHog Web Analytics - #60

Merged
Aliferous3 merged 1 commit into
mainfrom
feat/pageview-web-analytics
Sep 29, 2026
Merged

Aliferous3 merged 1 commit into
mainfrom
feat/pageview-web-analytics

Conversation

@Aliferous3

Copy link
Copy Markdown
Owner

Summary

Enables PostHog Web Analytics (visitors/pageviews/sessions, page breakdowns) without weakening the privacy model. Automatic capture stays off — a manual $pageview is emitted with a deliberately sanitized property set.

Mechanism: property_denylist strips every URL/referrer-derived field the SDK adds. before_send then re-attaches only the sanitized set — $current_url = origin + sanitized pathname, $pathname, $host, $referring_domain (bare domain only) — recomputed from window.location at send time. capturePageview() is the only entry point: zero caller properties, pathname-dedupe (StrictMode / hash / ?range= history entries can't double-emit), gated to devledger.site + localhost.

Wiring: initial emit after SDK init in main.tsx; useRoute's navigate + popstate cover client-side nav and back/forward.

Blog events/pageviews are emitted by the separate dev-ledger-site project (same PostHog project, same model).

Test plan

  • typecheck + build + 455 tests green
  • New tests: query/fragment strip, trailing-slash normalize, hostile-input collapse, referrer→domain only, internal-origin exclusion, $pageview not caller-emittable, dedupe, denylist→sanitize ordering
  • Post-merge: production $pageview observed through /rly

Generated with Devin

Web Analytics needs $current_url/$pathname on $pageview events, but
automatic capture stays off — the SDK would stamp raw location fields
(query, hash, referrer) before the scrubber could clean them.

- property_denylist still strips every URL/referrer-derived field;
  before_send re-attaches ONLY the sanitized set ($current_url,
  $pathname, $host, $referring_domain) recomputed from window.location
  at send time.
- capturePageview() is the sole $pageview entry point — zero caller
  properties, pathname-only dedupe (StrictMode / hash / ?range= safe),
  and emits only on the public host or local dev.
- Initial pageview fires after SDK init; useRoute's navigate/popstate
  cover client-side navigation and back/forward.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@vercel

vercel Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
dev-ledger Ready Ready Preview Sep 29, 2026 8:49pm UTC

@Aliferous3
Aliferous3 merged commit d0da2f8 into main Sep 29, 2026
5 checks passed
@Aliferous3
Aliferous3 deleted the feat/pageview-web-analytics branch September 29, 2026 20:50

This branch was successfully deployed

1 active deployment
Preview — f883451c Deployed Sep 29, 2026 by vercel[bot]
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