Skip to content

feat: add PostHog + event analytics to docs site#53

Merged
abrichr merged 1 commit into
mainfrom
feat/docs-posthog-analytics
Jul 21, 2026
Merged

feat: add PostHog + event analytics to docs site#53
abrichr merged 1 commit into
mainfrom
feat/docs-posthog-analytics

Conversation

@abrichr

@abrichr abrichr commented Jul 21, 2026

Copy link
Copy Markdown
Member

What

Adds privacy-safe analytics to docs.openadapt.ai (mkdocs-material) alongside the native Google Analytics integration. PostHog reuses the shared OpenAdapt project so all web properties report together.

Changes

  • overrides/main.html (new): Material overrides partial ({% extends "base.html" %}, {% block extrahead %}).
    • Emits the PostHog loader + posthog.init ONLY when NEXT_PUBLIC_POSTHOG_KEY is set at BUILD time ({% if config.extra.posthog_key %}). When unset, no PostHog script is present in the HTML at all: a hard no-op, not a disabled runtime path.
    • Respects Do-Not-Track (skips loading/init entirely). Uses person_profiles: 'identified_only', autocapture on, api_host from env.
    • Shared event taxonomy (always emitted, fully guarded so it never throws when analytics is off):
      • $pageview via Material's location$ observable (needed because navigation.instant is enabled). GA pageviews stay handled by Material natively.
      • docs_search {query_length} only, debounced ~800ms. Raw query text is never sent.
      • outbound_click {destination, href} where destination is app / download / github, href is host+path only (no query string).
  • mkdocs.yml:
    • theme.custom_dir: overrides.
    • GA made env-driven: property: !ENV [GOOGLE_ANALYTICS_KEY, "G-CJ01Y19XJN"] (public non-secret fallback keeps existing behavior). Note: origin/main currently has no extra.analytics block, so this also (re)activates GA with the founder's existing measurement ID.
    • posthog_key: !ENV [NEXT_PUBLIC_POSTHOG_KEY, ""] and posthog_host: !ENV [NEXT_PUBLIC_POSTHOG_HOST, "https://us.i.posthog.com"], reusing the marketing site's env var names + one PostHog project.
  • ANALYTICS.md (repo root, intentionally NOT under docs/ so it does not affect mkdocs build --strict nav): documents what is tracked, the env vars, DNT respect, and that no PHI/PII is involved (public docs only).

Env vars the founder must set at build time (in the docs deploy/CI env)

  • NEXT_PUBLIC_POSTHOG_KEY (same key as the marketing site)
  • NEXT_PUBLIC_POSTHOG_HOST (optional, default https://us.i.posthog.com)
  • GOOGLE_ANALYTICS_KEY (optional, default G-CJ01Y19XJN)

Verification

  • uv run mkdocs build --strict with NO PostHog env: passes; built site/*.html contains posthog.init( / array.js / person_profiles in 0 files. GA (G-CJ01Y19XJN) present.
  • uv run mkdocs build --strict with NEXT_PUBLIC_POSTHOG_KEY=phc_test: passes; posthog.init('phc_test', api_host: 'https://us.i.posthog.com', DNT guard present in all 51 pages. GA still present.
  • uv run pytest tests/: 64 passed.
  • uv run python scripts/validate_docs.py: Validation passed.
  • No real API key committed (phc_test used only via env at verify time). No em dashes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NyCHrzA1psrKMFfroYbzaM

Add privacy-safe analytics to docs.openadapt.ai (mkdocs-material) alongside
the native Google Analytics integration.

- overrides/main.html: Material overrides partial. Emits the PostHog snippet
  in extrahead ONLY when NEXT_PUBLIC_POSTHOG_KEY is set at build time (hard
  no-op otherwise). Respects Do-Not-Track, uses person_profiles:
  identified_only, autocapture on. Adds a shared-taxonomy event layer
  (docs_search with query_length only, outbound_click host+path only) plus a
  location$ pageview hook for Material's navigation.instant. Every call is
  guarded so it never throws when analytics is disabled.
- mkdocs.yml: register theme.custom_dir: overrides; make GA env-driven
  (GOOGLE_ANALYTICS_KEY, default G-CJ01Y19XJN); add build-time posthog_key /
  posthog_host env vars reusing the marketing site's names + one PostHog
  project.
- ANALYTICS.md (repo root, not published): documents what is tracked, env
  vars, DNT respect, and that no PHI/PII is involved.

Verified: mkdocs build --strict, pytest tests/, and validate_docs.py all
green. No PostHog script in built HTML when the key is unset; present when
NEXT_PUBLIC_POSTHOG_KEY=phc_test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyCHrzA1psrKMFfroYbzaM
@abrichr
abrichr merged commit a669da4 into main Jul 21, 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