Skip to content

fix(analytics): stop preview_loaded firing on every regeneration - #212

Merged
ceoloide merged 2 commits into
mainfrom
fix/preview-loaded-runaway-tracking
Nov 4, 2026
Merged

ceoloide merged 2 commits into
mainfrom
fix/preview-loaded-runaway-tracking

Conversation

@ceoloide

@ceoloide ceoloide commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Problem

The preview_loaded tracking effect in src/Ergogen.tsx listed configContext.results as a dependency. results is replaced on every auto-generation (300ms debounce while typing) and every background STL conversion, so preview_loaded re-fired for the same, unchanged preview on each regeneration.

GA4 impact (property 440040157, Jul 15 – Oct 28): ~209k preview_loaded events, ~37% of all event traffic. That much noise means the event can't tell us which outputs users actually look at, and it inflates event volume.

Fix

  • The effect now depends on a boolean hasResults rather than the results object.
  • A useRef stores the last tracked preview (key|extension). The event fires once when results first become available, and again only when the user switches to a different preview file.
  • The remembered preview is reset whenever results are cleared (selecting, creating or duplicating a config, or loading a shared link), so each config load still fires once even though Ergogen stays mounted.
  • Event name and parameters are unchanged (preview_type, preview_key), so existing GA4 reports keep working.

Tests

Added a preview_loaded tracking suite to src/Ergogen.test.tsx:

  • fires once when results first become available
  • does not re-fire across repeated regenerations of the same preview. This test fails on the previous implementation (4 events instead of 1).
  • fires again after results are cleared (config switch), even if the preview file is the same

pnpm run precommit passes (format, lint, Knip, 407/407 unit tests).

Notes

  • Expect preview_loaded volume to drop sharply after deploy. This is intended, not a usage drop.
  • Not included in this PR: pnpm-lock.yaml on main doesn't match package.json (ergogen is ^4.2.1 in the lockfile vs github:ceoloide/ergogen#v4.3.0 in the manifest), so a frozen-lockfile install fails.

The preview tracking effect in Ergogen.tsx depended on
`configContext.results`, which is replaced on every auto-generation
(300ms debounce while typing) and every background STL conversion. As a
result `preview_loaded` re-fired for the same, unchanged preview file on
each regeneration. In GA4 (Jul 15 - Oct 28) this produced ~209k events,
about 37% of all traffic, making the event useless for measuring which
outputs users actually inspect and inflating event volume.

The effect now depends only on whether results exist, and remembers the
last tracked preview (key + extension) in a ref. It fires once when
results first become available, and again only when the user switches
to a different preview.

Tests: added coverage in Ergogen.test.tsx asserting a single event on
first results and no re-fire across repeated regenerations (fails on the
previous implementation with 4 events instead of 1).
The previous commit remembered the last tracked preview to avoid
re-firing on every regeneration. Ergogen stays mounted when a config is
selected, created, duplicated or loaded from a shared link from the side
nav; those actions clear `results` and regenerate, typically showing the
same `demo.svg` preview. Because the remembered preview matched, those
loads stopped emitting `preview_loaded`, whereas they correctly fired
once before.

Reset the remembered preview whenever results are cleared, restoring one
event per config load while still suppressing regeneration repeats.
Generation failures keep the previous results, so they don't reset it.

Tests: added a case covering results -> null -> results with the same
preview, which fails without the reset (1 event instead of 2).
@ceoloide
ceoloide merged commit f3bdb73 into main Nov 4, 2026
2 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 4, 2026
…king

fix(analytics): stop preview_loaded firing on every regeneration
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