Repository navigation
[v36] Store analytics: record store impressions, clicks and purchase placement - #6447
Open
openfront-backport[bot] wants to merge 1 commit into
Open
openfront-backport[bot] wants to merge 1 commit into
openfront-backport[bot] wants to merge 1 commit into
Conversation
…ent (#6443) ## Description: Store analytics. The store now records which items players see and open, and where in the store each purchase came from. The data feeds a per-item baseline for the store. **Nothing visible changes.** > **Merge after the API change:** this needs the matching API change deployed first. The API ignores an unknown `placement` field and a missing `/store/events` route, so shipping early would not break purchases, but no data would be recorded. ### What each change does **`src/client/StoreTracking.ts` (new)** - `StoreTracker` counts an **impression** when a store card is at least half on screen for at least 1 second. Each item is counted once per store open. Scrolling a card in and out again doesn't count it twice. - It counts a **click** when a player opens an item, also once per item per store open. - Events are batched and sent to `POST /store/events`: - when they are sent: every 30 s, when the store closes, and when the tab is hidden or closed; - batch size: at most 200 events per request; - transport: `fetch` with `keepalive: true`, so the last batch survives the tab closing. - The auth header is read synchronously from the cached token. Sending never triggers a token refresh or any other network call. Signed-out players send no `Authorization` header. - Cards that Lit removes are released, so a long session doesn't keep them alive. A key longer than 120 characters is dropped rather than failing the batch. Patterns are counted under their base key, because one card shows every palette. - Send errors are swallowed and nothing about the player is logged. **`src/client/Auth.ts`** - Adds `peekAuthHeader()`, a synchronous, non-refreshing read of the cached token. Existing auth calls are unchanged. **`src/client/Store.ts`** - Starts a new "page view" on each store open, flushes on close, and watches every product tile. - Works out each card's **placement**: - the flash sale hero; - affiliate mode; - Cosmetics with its sub-tab (On sale, Skins, Flags, Crowns); - otherwise, the tab itself. - The store tab type now comes from the shared schema, so a new tab can't reach the API with a value it rejects. **Purchases: `Cosmetics.ts`, `Api.ts`, `Payments.ts`, `InlineCheckout.ts`, `WinModal.ts`** - Each purchase request carries the placement of the card the player bought from. That covers `/shop/purchase`, `/shop/purchase/pack` and `/payments/checkout`. - Post-game purchases send `post_game`. - When there is no placement, the field is left out. - Resolving the placement is wrapped so that it can never stop a purchase. **`packages/shared/src/ApiSchemas.ts`** - `StorePlacementSchema` and `StoreEventsBodySchema`, matching the API's copies. **`src/client/components/EffectsGrid.ts`** - Effect tiles get `data-cosmetic-key` so they're tracked like the other cards. ### Privacy policy `privacy-policy.html` now says what store analytics records: items shown and opened, where they appeared, the platform, and whether the player was signed in. It also says these events are not linked to an account, IP address or device id, and that no cookies or local storage are used. A purchase also records where in the store it was made. Raw events are kept up to 3 months, and daily totals per item may be kept indefinitely. The legal basis is legitimate interests, under the existing analytics row. Last Updated is now 11/16/2026. ### Screenshots There is no UI change, so instead here is the request the built client sent. How it was produced: - the branch's dev server, signed out; - the store catalog replaced with **sample data**: 30 test flags; - in Cosmetics → Flags, one card opened, then scrolled, then the store closed. The store sent one `keepalive` POST. It contained 9 impressions for the flags that had been on screen and one click: ```json { "platform": "web", "events": [ { "type": "impression", "item": "flag:test_flag_0", "placement": { "kind": "tab", "tab": "cosmetics", "subTab": "flags" } }, "… flag:test_flag_1 to flag:test_flag_8 …", { "type": "click", "item": "flag:test_flag_1", "placement": { "kind": "tab", "tab": "cosmetics", "subTab": "flags" } } ] } ``` ### Tests - New: `tests/client/StoreTracking.test.ts`. It covers: - the 1 s and 50% rule; - deduplication per store open; - batch splitting; - pagehide and hidden flushes; - keepalive sending, and sending without a token refresh; - released cards; - over-long keys. - Updated: `tests/client/StoreModal.test.ts`. It covers: - every tile having a key; - placements; - reopening the store counting again; - a failing placement never blocking a purchase. - Updated: `PaymentsCheckout.test.ts`, `PurchaseCosmeticPack.test.ts` and `GrantedSubscriptionPurchase.test.ts`. They check that the placement is in the request body, and that the key is absent when there is no placement. - Lint, typecheck and `build-prod` are clean. The homepage chunk doesn't gain the game client. ## Please complete the following: - [x] I have added screenshots for all UI updates (no UI change; the request body above stands in) - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file (no new text) - [x] I have added relevant tests to the test directory ## Please put your Discord username so you can be contacted if a bug or regression is found: iamlewis 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit f7d187a) Adjusted for v36 by Claude: the clean pick failed typecheck.
3 tasks done
Contributor
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
This branch was successfully deployed
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.
Cherry-pick of #6443 onto
v36. It applied cleanly but failed typecheck onv36, and Claude fixed it.Typecheck, format and lint pass on the result.
Check the fix before merging.