feat(ui): track solve_run analytics event - #20
Open
aeronauty-flexcompute wants to merge 1 commit into
Open
Conversation
GA4 carried only the six default events, so we could measure that people opened FlexFoil but not that they ran anything. Engagement time was the closest available proxy. Add a trackEvent helper to lib/analytics and fire solve_run from the three user-initiated solve paths in SolvePanel: single-point (alpha and CL targeting), alpha polar, and parameter sweeps. Params record which mode was used, viscous vs inviscid, and panel count. Fired at dispatch rather than completion so the count reflects solves requested, independent of convergence. Consent Mode still gates delivery, so this collects nothing extra from users who decline cookies. Co-Authored-By: claude-flow <ruv@ruv.net>
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.
Why
Vera asked whether FlexFoil is actually being used. GA4 could answer "people open it" (2,791 users YTD, 163 in the last 28 days, 5m29s average engagement) but not "people run solves" — the property carried only GA's six default events (
page_view,scroll,session_start,user_engagement,first_visit,click). Engagement time and ~12.7 page views per user were the closest available proxies.What
lib/analytics.ts: add atrackEvent(name, params)helper — a thinwindow.gtag?.('event', …)wrapper. Optional call becausegtagis absent when the tag is blocked.SolvePanel.tsx: firesolve_runfrom the three user-initiated solve paths:solve_modesingle_alpha/single_clrunAnalysis— single point, α or CL targetingpolarrunPolar— alpha polar sweepsweep_1d/sweep_2drunMultiSweep— parameter sweepsEach event also carries
solver_mode(viscous/inviscid) andn_panels.Events fire at dispatch, not completion, so the count reflects solves requested — independent of convergence, and it can't be lost to a throw or a hang.
Privacy
No change to the consent posture. Google Consent Mode still gates delivery, so this collects nothing extra from users who decline cookies. No airfoil geometry, coordinates, or filenames are sent — only the mode, solver type, and panel count.
Test plan
npx vitest run— 67 tests pass across 6 files, including 2 new cases inanalytics.test.ts(forwards name + params; does not throw when the tag is blocked). The new test stands up a minimalwindowonglobalThisso it runs in the existing node environment, avoiding a newjsdomdependency.npx tsc -b— clean.npx eslint— the changed analytics files are clean.SolvePanel.tsxreports 8 pre-existing problems (6 errors, 2 warnings, allreact-hooks/preserve-manual-memoizationin unrelated callbacks); verified identical count onmainbefore these edits, so this change adds none.npm run build— succeeds. Confirmedsolve_runand all fivesolve_modevalues survive intodist/assets/index-*.js(not tree-shaken).After merge
Merging to
maintriggersdeploy-foil.ymland ships to foil.flexcompute.com automatically.solve_runevent counts appear in GA4 (propertyFlexFoil) within ~24h under Engagement → Events. Thesolve_mode/solver_modeparams need registering as custom dimensions in GA4 admin to be reportable as breakdowns — the total event count and user count work without that.🤖 Generated with Claude Code
Note
Low Risk
Analytics-only UI changes with no solver, auth, or data-model impact; events use coarse metadata and existing consent gating.
Overview
Adds GA4 instrumentation so product usage can distinguish solve attempts from page views, without changing consent behavior or sending geometry.
A new
trackEventhelper inlib/analytics.tswraps optionalwindow.gtagcalls; Consent Mode still gates delivery, and blocked tags are a no-op.SolvePanelemitssolve_runat the start of each user-initiated solve path (before the job runs): single-point α/CL (single_alpha/single_cl), alpha polar (polar), and 1D/2D parameter sweeps (sweep_1d/sweep_2d). Each event includessolver_mode(viscous/inviscid) andn_panelsonly.analytics.test.tscovers forwarding togtagand safe behavior whengtagis missing.Reviewed by Cursor Bugbot for commit a295f0e. Bugbot is set up for automated code reviews on this repo. Configure here.