Add a local gameplay analytics dashboard - #52
Merged
Merged
Conversation
`npm run analytics:dashboard` serves the existing report as a page on 127.0.0.1:8788 and opens it: summary tiles, a daily starts chart split into finished, ended early and unfinished, game modes, winners, and every settings breakdown, with range and mode buttons. Each refresh runs the same fixed queries as `npm run analytics` through Wrangler's own login, so no analytics credential is published, stored in the browser, or added to the game. Cloudflare's Dashboards section cannot chart this data. Its D1 datasets report rows read, query latency and storage size, and its Workers Analytics Engine dataset groups only by dataset name, so none of them can break gameplay down by mode, difficulty or room. Extract the Wrangler-backed database adapter the CLI already used into tools/d1.mjs so both reports share one code path. `wrangler --json` reports API failures as a JSON object on stdout, which neither caller read, so a failed report printed Node's "Command failed" message with the full SQL attached. Parse that envelope, and when the failure is an authorization error while CF_API_TOKEN or CLOUDFLARE_API_TOKEN is set, name the variable and the command to run without it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PsSAuUXmXhyA173qE3Y3Fq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cloudflare's Dashboards section cannot chart gameplay analytics. Its dataset list offers Cloudflare's own telemetry:
D1 Analytics,D1 QueriesandD1 Storagereport rows read, query latency and storage size forastrapool-analytics, andWorkers Analytics Enginegroups only by dataset name. None of them read rows out of thegamestable, so they cannot break racks down by mode, difficulty or room.This adds a dashboard that runs the queries itself.
npm run analytics:dashboard # opens http://localhost:8788 npm run analytics:dashboard -- --port 9000 --local --no-openOne page holds the summary tiles, a daily starts chart split into finished, ended early and unfinished, game modes, winners, and all eight settings breakdowns, with buttons for the range (24 hours, 7, 30, 90 days) and the game mode. It serves the same
report()output asnpm run analytics, so the two always agree.It listens on
127.0.0.1only, and each refresh runs the fixed report queries through Wrangler's existing login. No analytics credential is published, stored in the browser, or added to the game, and the public Worker is unchanged.tools/d1.mjsholds the Wrangler-backed database adapter the CLI already had, so both reports share one code path.wrangler --jsonreports API failures as a JSON object on stdout, which neither caller read. A failed report printed Node'sCommand failedmessage with the full SQL attached, and said nothing about the cause. Both now print the API's own text, and when the failure is an authorization error whileCF_API_TOKENorCLOUDFLARE_API_TOKENis set, they name the variable and the command to run without it:Validation: 351 unit tests pass, including eight new ones covering the routes, filter validation, the report shape, query failures and that error message. Production build passes. Checked against the live
astrapool-analyticsdatabase: the dashboard andnpm run analytics -- --mode computerboth report 26 started, 21 finished, 80.8% completed. Every table and the chart were checked for clipping and overflow at 360, 480, 800 and 1180 px.🤖 Generated with Claude Code
https://claude.ai/code/session_01PsSAuUXmXhyA173qE3Y3Fq