Skip to content

feat(docs): expand PostHog instrumentation on the docs site - #505

Merged
jfwoods merged 4 commits into
mainfrom
posthog-instrumentation
Aug 20, 2026
Merged

feat(docs): expand PostHog instrumentation on the docs site#505
jfwoods merged 4 commits into
mainfrom
posthog-instrumentation

Conversation

@jfwoods

@jfwoods jfwoods commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

The site tracked its own CTAs but nothing readers did on the way to one. This adds the collection gaps from the analytics audit:

  • docs_search (query, result_count) — Pagefind queries, debounced to the settled query; zero-result searches are the point (docs gaps). Re-arms the settle check while a search is in flight so cold first searches aren't dropped.
  • code_copied (page, language) — Expressive Code copy buttons, delegated document-level; the hero install chip keeps its own hero_install_copied.
  • docs_404 (path, referrer) — broken inbound links become a list instead of a hunch.
  • live_demo_connected — once per mount when the hero's SSE feed comes up; named for what it measures (backend answered), not reader engagement.
  • doc_section on every event via a before_send hook — capture-time pathname, so the first hard-load pageview and soft navigations are both labeled correctly (a queued register() would replay after the first pageview is already captured).

New DocsTracking.astro hosts the three site-wide trackers, rendered from the footer like MermaidZoom/ScrollHints.

Test plan

  • make build-docs green (astro check, build, Pagefind index, links validator)
  • make verify green (docs-only change — classifier: code=false docs=true)
  • Built HTML greps: trackers present on index.html + 404.html, before_send hook emitted
  • Both pre-push reviewers ship_it (round 2, zero findings)

Related Issues

None — follow-up from the PostHog analytics audit (2026-08-20).

Adds the collection gaps found in the analytics audit:

- docs_search (query + result_count) from the Pagefind dialog, debounced
- code_copied (page + language) on Expressive Code copy buttons
- docs_404 (path + referrer) via the .wh-404 marker
- live_demo_engaged once per mount when the SSE feed connects
- doc_section stamped on every event via a before_send hook (capture-time
  pathname, so the first hard-load pageview and soft navigations are both
  labeled correctly)
- CHANGELOG: describe the shipped before_send mechanism for doc_section
  (the register()/astro:before-preparation wording documented an earlier
  iteration that never landed)
- Rename live_demo_engaged to live_demo_connected — it measures that the
  demo backend answered, not reader engagement
- docs_search: re-arm the settle check (3 x 400ms) when Pagefind is still
  searching when the idle timer fires, instead of silently dropping the
  query (biased against cold first searches)
- 404.md: record DocsTracking.astro as the third consumer of the .wh-404
  marker
@github-actions github-actions Bot added documentation Improvements or additions to documentation area/docs Documentation, site/, README labels Aug 20, 2026
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added analytics for documentation searches, including result counts and duplicate-query prevention.
    • Added tracking for code-copy actions, 404 pages, documentation sections, and live-demo connections.
    • Added shared documentation-section information to analytics events for improved reporting.
    • Added support for analytics across page transitions and repeated page loads.
  • Documentation

    • Documented analytics behavior and 404-page tracking requirements in the changelog and page comments.

Walkthrough

The docs site adds PostHog tracking for searches, code copies, 404 pages, documentation sections, live-demo connections, and CTAs. Tracking supports view transitions, delayed search capture, result counts, and one-time connection events.

Changes

Documentation analytics

Layer / File(s) Summary
Event enrichment and live-demo tracking
docs/src/components/PostHog.astro, docs/src/components/LiveDemo.astro
PostHog events now include doc_section. Live demos capture one live_demo_connected event per mount. CTA tracking uses the shared PostHog accessor.
Delegated documentation interaction tracking
docs/src/components/DocsTracking.astro, docs/src/components/Footer.astro, docs/src/content/docs/404.md, CHANGELOG.md
Delegated handlers track Pagefind searches, code copies, and 404 pages. The tracker is rendered site-wide. Comments and the changelog document the tracking behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🟡 Moderate · up to e2420

The change expands analytics collection but may send sensitive raw search or URL-derived values and can mislabel searches after client-side navigation; repeat visits to the same 404 page may also be missed. Merge should wait for sanitization and lifecycle fixes or explicit owner acceptance.

Sequence Diagram(s)

sequenceDiagram
  participant Document
  participant DocsTracking
  participant Pagefind
  participant PostHog
  Document->>DocsTracking: receive search, copy, or 404 interaction
  DocsTracking->>Pagefind: inspect search results while loading
  DocsTracking->>PostHog: capture event with interaction metadata
Loading

Suggested reviewers: taitelee

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: expanded PostHog instrumentation for the documentation site.
Description check ✅ Passed The description directly explains the analytics events, implementation, and validation steps included in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch posthog-instrumentation
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch posthog-instrumentation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

📚 Docs preview is livehttps://2ba41ec3-wavehouse-docs.wave-rf.workers.dev

  • Commit2ca48de: Merge branch 'main' into posthog-instrumentation
  • Author@jfwoods
  • Committed — 2026-08-20 12:54 (UTC-04:00)
  • Deployed — 2026-08-20 12:58 EDT

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b673daa6-2e13-46b0-b364-c8a4a844028e

📥 Commits

Reviewing files that changed from the base of the PR and between d3c4a53 and cd1119d.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • docs/src/components/DocsTracking.astro
  • docs/src/components/Footer.astro
  • docs/src/components/LiveDemo.astro
  • docs/src/components/PostHog.astro
  • docs/src/content/docs/404.md

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Docs build
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{go,ts,tsx,js,jsx,md,mdx,yaml,yml,json}

📄 CodeRabbit inference engine (AGENTS.md)

Every code change updates its docs + CHANGELOG.md in the same PR

Files:

  • docs/src/content/docs/404.md
  • CHANGELOG.md
**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

  • Never hard-wrap prose. One paragraph is one line. No wrapping at 72/80 columns, no "semantic linefeeds" splitting a paragraph at sentence boundaries.

Files:

  • docs/src/content/docs/404.md
  • CHANGELOG.md
🪛 LanguageTool
CHANGELOG.md

[style] ~13-~13: Since ownership is already implied, this phrasing may be redundant.
Context: ...ter,LiveDemo}.astro`): the site tracked its own CTAs but nothing a reader did on the wa...

(PRP_OWN)


[style] ~13-~13: Since ownership is already implied, this phrasing may be redundant.
Context: ...docs area without each tracker carrying its own copy; it's stamped at capture time by a...

(PRP_OWN)


[style] ~13-~13: Since ownership is already implied, this phrasing may be redundant.
Context: ...ressive Code, and the 404 route all own their own markup — some of it created after page ...

(PRP_OWN)

🔇 Additional comments (5)
docs/src/components/PostHog.astro (1)

34-45: LGTM!

docs/src/components/LiveDemo.astro (1)

169-173: LGTM!

Also applies to: 431-444, 525-528

docs/src/components/DocsTracking.astro (1)

68-82: LGTM!

docs/src/components/Footer.astro (1)

17-17: LGTM!

Also applies to: 189-195

CHANGELOG.md (1)

11-13: LGTM!

Comment thread docs/src/components/DocsTracking.astro Outdated
Comment thread docs/src/components/DocsTracking.astro
Comment thread docs/src/content/docs/404.md
@github-project-automation github-project-automation Bot moved this from Backlog to In review in WaveHouse Task Board Aug 20, 2026
@jfwoods
jfwoods marked this pull request as ready for review August 20, 2026 15:31
@jfwoods
jfwoods requested review from a team and taitelee August 20, 2026 15:31
CodeRabbit: a reader can click a result before the debounce or a retry
fires; capturing then stamps the event with the destination page's
doc_section. Bind the timer to its source pathname and drop the capture
when it no longer matches.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/src/components/DocsTracking.astro (1)

53-60: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Key 404 de-duplication by page instance, not pathname.

window.__whPh404Path is never reset. After client-side navigation away from a 404 page and back to the same location.pathname, whCapture404() drops the second visit. This records once per pathname for the document lifetime, although the comment says “once per visit.”

Store the current .wh-404 element, or reset the key on each route transition, so duplicate lifecycle callbacks are suppressed without dropping later visits.

Proposed fix
 function whCapture404() {
-  if (!document.querySelector('.wh-404')) return;
-  if (window.__whPh404Path === location.pathname) return;
-  window.__whPh404Path = location.pathname;
+  var marker = document.querySelector('.wh-404');
+  if (!marker || window.__whPh404Marker === marker) return;
+  window.__whPh404Marker = marker;
   window.posthog?.capture('docs_404', {

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3d27a110-656b-4f87-a897-5991bc9ced46

📥 Commits

Reviewing files that changed from the base of the PR and between cd1119d and e242065.

📒 Files selected for processing (1)
  • docs/src/components/DocsTracking.astro

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Review details
🔇 Additional comments (2)
docs/src/components/DocsTracking.astro (2)

17-21: LGTM!

Also applies to: 34-34, 68-68


22-47: LGTM!

Also applies to: 63-86, 90-91

@github-project-automation github-project-automation Bot moved this from In review to In progress in WaveHouse Task Board Aug 20, 2026
@jfwoods
jfwoods enabled auto-merge August 20, 2026 16:55
@jfwoods
jfwoods added this pull request to the merge queue Aug 20, 2026
Merged via the queue into main with commit b65052e Aug 20, 2026
20 checks passed
@jfwoods
jfwoods deleted the posthog-instrumentation branch August 20, 2026 17:01
@github-project-automation github-project-automation Bot moved this from In progress to Done in WaveHouse Task Board Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation, site/, README documentation Improvements or additions to documentation

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants