Repository navigation
Conversation
npm run insights queries PostHog, rebuilds insights/index.html, and (with --check) renders it headlessly in light, dark and mobile, failing on console errors, horizontal overflow, or a missing chart. The page is one self-contained file: fonts inlined from @fontsource as data URIs and hand-rolled SVG charts, because it is published as an Artifact where a strict CSP blocks every external request. - scripts/insights/queries.mjs holds named HogQL queries, each with an explicit LIMIT (PostHog silently caps ungoverned results at 100 rows, which truncates group-by output) and one shared self/datacenter city list, so the daily series and the profile breakdown can no longer disagree - scripts/insights/notes.json holds the interpretive prose separately from the data, with a writtenFor range; the build warns when the data moves past it, since a rerun refreshes numbers but never sentences - prose can embed {{tokens}} (topDays, profiles, failed, ...) so claims that are really derived stats update themselves - output is gitignored; --offline rebuilds from the cached query results - POSTHOG_API_KEY documented in .env.example, flagged as a real secret unlike the publishable VITE_* values eslint: the Node-side block now also declares browser globals, since these files author page.evaluate callbacks that execute in the browser.
prettier --check covers it now that the gitignore rule is anchored to /insights/; before that the unanchored pattern also matched scripts/insights/ and prettier skips gitignored files, so it was never checked locally. Whitespace only: the generated page's data, prose and render checks are unchanged.
The page was half dashboard, half write-up: the callout described one
specific machine's failures, and other copy named users and called out
particular days. None of that survives a rerun, so every rebuild needed
prose review before it was publishable.
Now every string in notes.json explains what a number measures and how to
read it, and nothing describes a particular week. The convention is stated
at the top of that file. Incident and trend analysis belongs in a blog post
or an issue, where it can be dated.
- the hand-written callout is replaced by a failure-reasons table built from
the failures query, which was already being fetched and never displayed
- {{topDay}} replaces a typed-in list of spike dates
- writtenFor and the staleness warning are gone; they existed to guard prose
that no longer exists
- the self bucket label no longer hardcodes a city from queries.mjs
Any rerun is now publishable as-is.
|
Updated: the page is now definitional rather than dated, so any rerun is publishable without reviewing prose. The first version was half dashboard, half write-up. It named specific users, called out particular days, and had a callout describing one machine's SIMD failures. None of that survives a rerun, which is why the build had to warn about stale narrative. Rather than warn about the problem, the prose that caused it is gone. Every string in
Incident and trend analysis belongs in a blog post or an issue, where it can carry a date. The convention is stated at the top of Consequent changes:
The earlier CI failure is fixed: |
Makes the analytics page from the first-month writeup reproducible, so it can be rebuilt against fresh data instead of being a one-off.
Usage
Needs
POSTHOG_API_KEYin.env. Unlike theVITE_*values this one is a real secret, so.env.examplenow documents it with that warning. Output is gitignored.Layout
scripts/insights.mjs— query, shape, interpolate, render check.scripts/insights/queries.mjs— named HogQL queries.scripts/insights/notes.json— the prose.scripts/insights/template.html— the page, with{{token}}slots.The page is a single self-contained file: fonts are inlined from
@fontsourceas data URIs and the charts are hand-rolled SVG (about 150 lines), because it is published as an Artifact where a strict CSP blocks every external request. No chart library is reachable there.Two things worth reviewing
Prose goes stale in a way numbers do not. A rerun refreshes every figure but cannot refresh a sentence like "three spikes carry the month". So the narrative lives in
notes.jsonwith awrittenForrange, and the build warns when the data has moved past it:Claims that are really derived stats use
{{tokens}}instead and update themselves. That immediately caught one of my own errors: I had hand-written the spike days as "July 24, 26 and 27", but the top three days by completed conversions are July 26, 27 and 29. I had misread the started column. The generated text is correct.Query correctness. PostHog applies an implicit
LIMIT 100to HogQL when the query does not set one, which silently truncates group-by results; that bit me while exploring, so every query here sets an explicit limit. The self and datacenter city lists are now defined once and shared, which fixes a real inconsistency in the published page, where the daily series excluded 3 datacenter cities and the profile breakdown excluded 4. One Ashburn profile was counted differently by the two. The artifact has been republished from this script's output.Verification
npm run insights -- --checkfrom a clean checkout reproduces 34 days, 624 conversions and 137 profiles, and passes all three render checks (light, dark, 420px) with zero console errors and no horizontal overflow. Lint, format, typecheck and the 123 unit tests all pass. Verified the API key does not appear in the generated HTML.The eslint change adds browser globals to the existing Node-side block, since these files author
page.evaluatecallbacks that run in the browser. The e2e specs already did this and only escaped the rule becauseno-undefis off for TypeScript.