Skip to content

Fix flash counter: count completions via state-changed event + Abacus (no session dedup) - #40

Merged
DrewFerg11 merged 4 commits into
mainfrom
flash-counter-fix
Aug 8, 2026
Merged

Fix flash counter: count completions via state-changed event + Abacus (no session dedup)#40
DrewFerg11 merged 4 commits into
mainfrom
flash-counter-fix

Conversation

@drewferg11-hermes-bot

Copy link
Copy Markdown

Problem

The flash counter on the web flasher page has two accuracy issues:

  1. Counts clicks, not completions — the counter fires on button click, not on successful flash completion. Someone who clicks Install but cancels the dialog still gets counted.

  2. Session deduplication — the counter uses GoatCounter pageviews, which deduplicate per visitor session (8h). Flashing 3 boards in one sitting counts as 1.

The completion detection was also fragile: it wrapped Lit's private _installState accessor on the ewt-install-dialog prototype, which would silently break on any ESP Web Tools version update that renames the property.

Fix

1. Count completions via public state-changed event

ESP Web Tools' ewt-install-dialog dispatches a public state-changed CustomEvent with detail being the state string (initializing, preparing, erasing, writing, finished, error). This is a stable public API — no private property hacking.

The new code:

  • Watches document.body for ewt-install-dialog elements (appended by ESP Web Tools when a flash starts)
  • Listens for state-changed events on each dialog
  • Increments the counter only when state === "finished"" — actual successful completions, not clicks or cancelled dialogs

2. Abacus replaces GoatCounter for flash counting

Abacus is a free, stateless counting API with CORS support. Each /hit call increments by 1 — no session deduplication. Flashing 3 boards in one sitting now counts as 3.

The badge reads the Abacus counter on page load and displays the total without the old "at least" qualifier (since the count is now accurate, not a floor).

GoatCounter stays for site analytics

GoatCounter is still loaded site-wide for pageviews and feedback ratings (via overrides/partials/integrations/analytics/custom.html). Only the flash completion counter moved to Abacus.

What changed

  • docs/firmware/install-web-flasher.md — replaced the GoatCounter flash counter script (220 lines) with a 100-line Abacus + state-changed script. All other scripts (erase dialog, version picker, keyboard fix) are untouched.

Trade-offs

  • Abacus is a free third-party service (hosted on Fly.io, backed by Valkey). If it goes down, the badge stays hidden (fail-silent) but flashing is unaffected. The old GoatCounter approach had the same single-point-of-failure.
  • Counter starts from 0 — the old GoatCounter count ("at least 11") is not migrated. The badge will be hidden until the first new flash completes, then show the accurate count from there.
  • No analytics dashboard — Abacus only stores a raw number. The old GoatCounter event paths (/flash/finished/factory, /flash/failed/factory) which showed success/failure ratios in the GoatCounter dashboard are removed. If you want those back, they can be added as GoatCounter events alongside the Abacus counter.

Two fixes:
1. Count completions not clicks: listen for ESP Web Tools' public
   "state-changed" CustomEvent on ewt-install-dialog, increment only
   on "finished" state. Replaces the fragile _installState accessor
   hack.
2. No session dedup: Abacus (abacus.jasoncameron.dev) is a free
   stateless counting API with CORS support. Each /hit increments by 1
   with no per-session deduplication (unlike GoatCounter pageviews
   which counted N boards in one sitting as 1).

GoatCounter is still used for site-wide analytics (pageviews, feedback
ratings) — only the flash completion counter changed.

@drewferg11-claude-bot drewferg11-claude-bot 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.

The state-changed/Abacus approach is a solid improvement over the private _installState hack, and the Abacus fail-silent handling looks right. One blocking issue found in the diff, otherwise this looks good to merge.

Comment thread docs/firmware/install-web-flasher.md Outdated
Remove literal backslash-n accidentally appended to continue; line,
causing a JS syntax error that would break release list population.
@DrewFerg11
DrewFerg11 merged commit 30c9a85 into main Aug 8, 2026
11 checks passed
@DrewFerg11
DrewFerg11 deleted the flash-counter-fix branch August 8, 2026 14:26
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