Repository navigation
fix(analytics): stop preview_loaded firing on every regeneration - #212
Merged
Merged
Conversation
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).
github-actions Bot
pushed a commit
that referenced
this pull request
Nov 4, 2026
…king fix(analytics): stop preview_loaded firing on every regeneration
3 tasks
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.
Problem
The
preview_loadedtracking effect insrc/Ergogen.tsxlistedconfigContext.resultsas a dependency.resultsis replaced on every auto-generation (300ms debounce while typing) and every background STL conversion, sopreview_loadedre-fired for the same, unchanged preview on each regeneration.GA4 impact (property 440040157, Jul 15 – Oct 28): ~209k
preview_loadedevents, ~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
hasResultsrather than theresultsobject.useRefstores 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.Ergogenstays mounted.preview_type,preview_key), so existing GA4 reports keep working.Tests
Added a
preview_loaded trackingsuite tosrc/Ergogen.test.tsx:pnpm run precommitpasses (format, lint, Knip, 407/407 unit tests).Notes
preview_loadedvolume to drop sharply after deploy. This is intended, not a usage drop.pnpm-lock.yamlonmaindoesn't matchpackage.json(ergogenis^4.2.1in the lockfile vsgithub:ceoloide/ergogen#v4.3.0in the manifest), so a frozen-lockfile install fails.