Repository navigation
fix: send sort_finish once when each board finishes - #69
Merged
Merged
Conversation
The completion effect in App ran whenever `playing` or any board's `finished` flag changed, and it sent `sort_finish` for every board that had already finished. One playback therefore sent the event several times for the algorithms that finished early (for example quick_sort 4 times), and pausing, resuming, or pressing play after every board had finished sent all of them again. Send the event from one effect per board that runs when that board's `finished` flag changes, so it fires once when the board finishes. `useEffectEvent` reads the speed, bar count, and language at that moment without making them dependencies. A shuffle or a bar count change resets the boards, so the next completion is sent again. The event name and parameters are unchanged. Add UI tests that record the calls to `window.gtag`, and note the rule in AGENTS.md and the add-sort-algorithm skill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
GA4 の
sort_finishが、1回の再生で同じアルゴリズムについて複数回送られていたのを、各ボードが完了したときに1回だけ送るように直しました。原因
src/App.tsxの完了を扱う effect は、playingかいずれかのボードのfinishedが変わるたびに実行され、その時点で完了しているボードすべてのsort_finishを送っていました。そのため、先に完了したアルゴリズムほど、ほかのボードが完了するたびに送り直されていました。一時停止・再開や、全ボードの完了後に再生を押したときも、完了済みの分をすべて送り直していました。UIテストで
window.gtagに渡ったイベントを数えた結果です(20本、テストで固定した乱数の並び)。quick_sortselection_sortbubble_sortmerge_sort変更した仕様・設計
ボードごとに、
finishedが変わったときだけ実行される effect から送ります。速度・本数・言語は、useEffectEventで送る時点の値を読みます(依存に入れると、完了後に速度を変えただけで送り直すため)。全ボードの完了で再生を止める処理は、これまでどおり別の effect に残しました。イベント名と引数(animation_speed・bar_size・algorithm_type・browser_language・translated_language)は変えていません。flowchart LR subgraph before["修正前"] A1["playing か、いずれかの finished が変わる"] --> B1["完了済みのボードすべての sort_finish を送る"] end subgraph after["修正後"] A2["あるボードの finished が false から true になる"] --> B2["そのボードの sort_finish を1回送る"] end送り直すかどうかは、次のとおり判断しました。
sort_finishは、AGENTS.md の約束ではalgorithm_type: '<kind>_sort'を持つ、アルゴリズムごとの並べ替えの完了を表すイベントです。一時停止・再開や、完了後に再生を押す操作では並べ替えが完了しない(完了済みのボードは進まず、再生はすぐ止まる)ため、送りません。AGENTS.md と add-sort-algorithm の skill に、
sort_finishは各ボードの完了時に1回送ることを書き足しました。検証
src/__tests__/ui.spec.tsxに2件を加えました。window.gtagに渡ったイベントを記録します。sort_finishを1回ずつ、正しい引数で送る。play_click・pause_click・shuffle_click)は操作ごとに1回ずつ送る。src/App.tsxでは落ち(回数は上の表)、修正後は通ることを確かめました。yarn typecheck && yarn lint && yarn format && yarn test: 成功(46件)。http://localhost:1234、StrictMode で動く)の/ja/を、内蔵ブラウザで実際に操作しました。index.tsxが本番の測定IDで GA を初期化するため、本番の計測に送らないよう、同じオリジンの文書にlocalhost:1234だけを許す Content-Security-Policy を置いてから、/ja/のスクリプトを読み込みました。gtag.js の読み込みは CSP で止まり、Google への通信は0件でした。gtag に渡った引数はwindow.dataLayerで確かめました。sort_finishは4つを1回ずつ(bar_size: 5、animation_speed: 10)。2回目の再生はplay_clickだけで、すぐ止まる。4パネルとも昇順で完了の表示sort_finishは4つを1回ずつ(非表示のmerge_sortも1回)。再生の2回はplay_clickだけ。マージソートを表示し直すと、1〜20の昇順と「並べ替えが終わりました。」を表示shuffle_click1回。ステップ数が4パネルとも0に戻り、同じ新しい並びになるpause_click・play_clickを1回ずつ送り、quick_sortを送り直さない。残りの3つは完了時に1回ずつ。4パネルとも昇順で、比較枠は残らないアニメ速度: 9.95になり、イベントは送らない全体では、
sort_finishは3回の再生(5本・20本・50本)で各アルゴリズム1回ずつ、play_click7回・pause_click1回・shuffle_click1回で、押した回数と一致しました。🤖 Generated with Claude Code