v1.0.10 · Release snapshot

Documentation comes from this release commit, without inheriting newer content. Commit: 63ea8c2b3d.

Analytics events

Analytics is schema-driven. Event param shapes live in Valibot schemas; typed track() contracts are derived from them. You never hand-write event constants or call the Firebase SDK directly from a feature.

Schema shape

Each event is a Valibot v.object({ … }) keyed by canonical snake_case name:

// packages/analytics/src/event-schemas.ts
export const eventSchemas = {
  song_click: v.object({
    song_session_id: v.optional(v.string()),
    song_id: v.optional(v.string()),
    // …
  }),
  videoads_trigger: v.object({
    screen: v.optional(v.picklist(["song_unlock", "revive"])),
    location: v.optional(v.picklist(["home", "result", "shop", "others", "revive"])),
    reward: v.optional(v.picklist(["song_unlock", "revive", "song_learn"])),
    song_id: v.optional(v.string()),
    song_name: v.optional(v.string()),
  }),
} as const;

Types derive automatically:

// event-types.ts
export type AnalyticsEventMap = {
  [K in keyof typeof eventSchemas]: v.InferOutput<(typeof eventSchemas)[K]>;
};

App/ad code imports taxonomy types from @piano/analytics (schema-types.ts) — AnalyticsParam, RewardedAdContext, VideoadsStamp, reviveRewardedContext(), etc. — all derived from AnalyticsEventMap, not hand-written unions.

Layers

LayerFileRole
Valibot schemasevent-schemas.tsSingle source of truth — event names, params, enums.
Derived typesevent-types.tsAnalyticsEventMap, AnalyticsEventName via v.InferOutput.
Runtime validationdispatcher.tstrack() validates against schemas — strips unknown keys, rejects bad enums in dev/test.
Schema typesschema-types.tsApp-facing aliases (RewardedAdContext, reviveRewardedContext(), …).
Routingevent-routing.tsProvider fan-out, AppsFlyer name overrides, AUTO_SDK_EVENTS.
Contractevent-contract.tsstatus + trigger file paths for CI wiring tests.

Adding / changing an event

  1. Edit packages/analytics/src/event-schemas.ts. Keep the name snake_case and globally unique.

  2. Update routing in event-routing.ts (which providers receive the event).

  3. Update contract in event-contract.ts (status, trigger path once implemented).

  4. Implement the call site in a feature using the typed API:

    import { trackEvent, newSongSessionId } from '@core/sdk/analytics';
    trackEvent('song_click', { song_session_id: newSongSessionId(), song_id: id });

    Or in a component via the hook: const a = useAnalytics(); a.track(...). FTUE funnel events use trackFtueSessionEvent / trackFtueEvent from src/core/sdk/ftue-analytics.ts — they stamp the persisted session counter (incremented once per cold start via bindFtueSession() in the root layout). Cold-start boot events (fn_loading_start, fn_loading_end, fn_after_splash_screen) go through useTutorialStore((st) => st.trackBootEvent) so the store gates once-per-install firing and skips after onboarding + tutorial complete. Those events and fn_intro_1 also carry elapsed_ms (ms since JS entry, stamped by js-entry-mark); fn_loading_end adds status = ok | degraded (a boot service threw or timed out) | ceiling (the 8 s services ceiling released the app first). It now fires whenever the guarded service chain settles — not only when the hub bootstrap succeeded — so a drop between fn_loading_start and fn_loading_end means the app was killed/crashed, not that a service failed. fn_loading_start fires when loading starts — after the 2.8 s splash intro (boot runs only once the intro has played), so its elapsed_ms includes the intro. boot_timing (once per cold start, not install-gated) reports per-service latency (rc_ms, iap_ms, hub_ms), js_entry_ms (React Native startup → JS entry = bundle-load time), status, failed_step and ceiling_hit; it goes out at the ceiling if that comes first, so a hung service is named. splash_timing (once per cold start, not install-gated) fires when the splash has gone (useHideSplash) and says how long it ran: splash_ms (bundle load + JS entry → gone; the native launch before JS is not counted), intro_ms (the JS splash intro, 0 when it never took over), loading_ms (loading start → the services releasing the splash; absent when they never did), wait_ms (that release → gone: the last gates and the 3 s minimum) and ceiling_hit (the 12 s hard ceiling released it). fn_after_splash_screen carries the same splash_ms for the FTUE funnel. The app version is on every event via the app_version / app_build user properties. Firebase Performance traces (boot_total, boot_<step>) mirror the same timings — see Boot performance. onboarding_perf fires when the onboarding screen goes (useOnboardingPerf): the UI thread's frame rate while it was in view — counted from the splash going, since the screen mounts under it (avg_fps, low_fps = worst second, jank_pct = frames over twice the budget, max_fps = 60 or 120 Hz, duration_ms; a Reanimated frame callback, frame-stats), the JS thread's (js_avg_fps), film_ms (screen open → the film's first frame) and thumbs_ms / thumbs_ok (the boot prefetch of the tutorial songs' covers, absent while it is still running). fn_next_song_after_tutorial goes through useTutorialStore.getState().trackNextSongAfterTutorial from PlayScreen — once per install when the first post-tutorial session starts (tutorial_next from Get or home from the song list). Song engagement events use helpers in src/core/sdk/song-analytics.ts — trackSongImpression (2s visibility) is meant to begin the song_session_id funnel, but nothing calls it yet (see Known tracking issues); trackSongClick starts the session, or reuses the song's active one. song_order must be the 1-based position in the visible on-screen list via songListOrderFromIndex / songListOrderFromId — never catalog sortOrder from the remote sheet. It goes out only on home and recommended_result plays (songOrderForPlayType drops it for every other play type), and only when such a list opened the play: Home's filteredTracks (Game Mode and the Learn CTA) and Game Mode's Result recommendations. Learn's result Next song is recommended_result with no song_order: it is one suggestion, not a list row. Set status: "implemented" and a trigger file path in event-contract.ts once it's merged.

  5. Test: cd packages/analytics && bun test — contract tests verify trigger files exist and actually call track() for implemented events.

Param / trigger descriptions in schema

PM-facing semantics live on the Valibot schema via v.pipe(..., v.description("…")) — not sent to Firebase. Reuse shared fragments in event-schema-fragments.ts (e.g. videoadsScreen, videoadsLocation) so revive copy is defined once.

export const videoadsScreen = v.pipe(
  v.optional(v.picklist(["song_unlock", "revive"])),
  v.description("revive = learn mode out-of-hearts Continue → earn 1 heart …"),
);

videoads_trigger: videoadsEvent(
  "User tapped Watch ads — unlock or learn revive.",
  { ...videoadsContextEntries, song_id: videoadsSongIdOptional },
),

Read descriptions at runtime or for docs export:

import { getEventTriggerDescription, getEventParamDescriptions, buildEventDocRegistry } from '@piano/analytics';

getEventTriggerDescription('videoads_trigger');
getEventParamDescriptions('videoads_show').location;
buildEventDocRegistry(); // flat list for PM / visualizer

Event-level v.description() = when the event fires. Field-level = when to stamp each param. File wiring stays in event-contract.ts (trigger path).

Videoads context

All videoads_* events share the same param fields (screen, location, reward, song_id, song_name). Stash context before showRewarded():

  • Song unlock: songUnlockRewardedContext(songId, songName, mode) → screen: "song_unlock"; mode: "learn" (the unlock opens the song in Learn) adds reward: "song_learn"
  • Learn revive: reviveRewardedContext(songId, songName) → screen: "revive", location/reward: "revive"

The Song List's Learn CTA on a rewarded row shares the Play CTA's unlock, so it shares its context too — the same songUnlockRewardedContext — bound for Learn, so its reward is song_learn — and the same unlock_song placement. Its order is song_click (song_mode: "learn", on the press) → the sheet → videoads_* (on "Learn this song for free", after the sheet dismisses) → Learn Mode's own session events. No second song_click: the session guard in trackSongClick has already fired one for that session, and the Learn CTA reuses it. See features/songs.md.

See src/core/sdk/ad-analytics-track.ts.

App Open (openads_*) — the AdMob App Open format (cold launch and return from the background, ad-trigger-logic.md §6) reports Guitar's nine events, in Piano's naming. All are Firebase-only:

EventFires when
openads_requesta load goes out
openads_request_successthe load succeeds
openads_request_failedthe load fails; carries fail_reason
openads_show_readyan ad is in hand at show time
openads_show_notreadythe show has nothing to show; carries fail_reason, no unit
openads_showthe ad is displayed
openads_show_failedthe ad was in hand but never displayed; carries fail_reason
openads_finishthe ad is closed
openads_clickthe player taps the ad

Params:

  • Every event carries accumulated_count, plus ad_unit_tier and ad_unit_id except on a notready. The count is the user's lifetime total for that event, kept in useEventCountStore; it is read from memory at once but saved to MMKV in batches (eventCountStorage: one write per ~1.5 s window on the idle queue, and at once when the app leaves the foreground), so a process that dies inside the window can lose the last few counts.
  • Every event carries location: app_open (the cold launch), foreground_return (a return) or others (a preload, or the refill after a show).
    • A request, its success and its failure name what the load was for when the request went out.
    • The show-side events name the show's placement.
  • The three request events also carry att_status, as fullads_request* do.

openads_show_notready has three sources:

  • launch_wait_5s: the launch waited 5 s and nothing loaded.
  • show_no_ready: a return found nothing loaded.
  • show_no_ready: the ads engine found no ad at show time.

A gate that stops the App Open sends nothing (premium, FTUE, fewer than 4 finished songs, the 120 s / 60 s gaps, a menu that is covered), as in Guitar. There is no openads_trigger.

The paid event sends ad_impression / ad_impression_ama with ad_format: "app_open" and ad_unit_name: "Open_All" (Guitar's name), plus AppsFlyer af_ad_revenue. There is no AppsFlyer custom event. See app-open.ts and ad-analytics-track.ts.

Ad funnel params (fullads_*, videoads_*, bannerads_*)

A funnel event that stands for one AdMob unit names it — ad_unit_tier (high / all) and ad_unit_id (the full ca-app-pub-…/… id); *_trigger and videoads_backfill carry none, and so does *_show_notready now — it only fires when neither tier is loaded, so there is never a unit behind it. An empty show is only that: *_show_failed keeps its own meaning — an ad was in hand and never reached the player — and always names the unit it had. The engine mirrors magicPad's tier cache policy (two tiers kept loaded per format, an unbounded 5 s → 60 s retry ladder, a 90 s load timeout (magicPad: 60 s), eviction after 3 skipped shows) — except that the High tier of the interstitial and rewarded retries on its own, slower ladder (30 s, 1, 2, 4 minutes, then every 5 minutes) that a song start or an empty show never cuts short, after AdMob flagged High's failed requests; so *_request on High units is far rarer than in magicPad — and every attempt now reports its own *_request → *_request_success / _failed — retries included, not just the first load of a tier. In Game Mode, the requests a song needs go out on its loading screen, which holds the countdown up to 5 s for the interstitial; from the countdown until the player leaves the song nothing new is requested, so a *_request never lands mid-song. The banner reports the same three-event shape on the same ladder: bannerads_request / _request_success / _request_failed, alongside the existing bannerads_show / _empty / _click. Since 2026-10-05 the app keeps one banner loaded ahead, so a banner request can precede any banner screen: it then carries no location, and bannerads_show fires when the banner appears in a screen's slot, not when it loads. No banner request goes out from a Game Mode song's countdown until its last note has ended.

fullads_request, fullads_request_success and fullads_request_failed also carry att_status (since 2026-10-07): the iOS App Tracking Transparency status the request went out under — granted (the IDFA is readable), denied (iOS "restricted" included) or undetermined (both: no IDFA). Android has no prompt and sends none. It is there to split interstitial no-fill by whether the networks could see the IDFA; videoads_* and bannerads_* do not carry it. Until 2026-10-19 a status other than granted also meant non-personalised ads only; since then the request is the same for every status.

fail_reason is the SDK's <code>: <message> or an app-side reason, at most 100 characters. New app-side values: both_tiers_empty / show_no_ready (an empty interstitial / rewarded show — magicPad's own wording, never with a unit named, and on *_show_notready only), load_timeout_90s (a load the SDK never answered within 90 s — load_timeout_60s before 2026-10-07), reward_not_earned (a rewarded the player closed before earning it). Retired: sdk_not_loaded no longer reaches any event — the tier is simply not picked, and the reason stays in the ads log only. retry_count is still not a param (it never was); what changed is that a retry now shows up as its own *_request event instead of nothing. Details: admob-integration.md §8.

Song sessions across Game Mode and Learn Mode

  • song_mode (game | learn) is stamped on every song_* event except song_impression, song_preview, song_pause and song_pause_action. The shared builders in src/core/sdk/song-analytics.ts and song-engagement-run.ts default to game, and Learn names its own. The Game Mode result's recommendation column names it too now that it has a Learn/Play toggle: a card tapped on the Learn half opens Learn Mode, so trackResultRecommendationSongClick stamps song_mode: "learn" on it rather than letting it default to game.

  • song_version rides on every event that carries song_mode: default for the song's own MIDI, otherwise the name of the version Remote Config song_versions assigned (short; see features/catalog.md). Game Mode session events report the chart that loaded (useMagicGameplay's playedVersionRef), so a version that could not be had and fell back reports default. The Song List, Replay and result recommendation clicks report the version the play will load. Learn Mode, the tutorial's own song (it plays its tutorial_song MIDI) and song_impression report default.

  • Learn Mode opens after four finished songs (features/songs.md), and the lock adds no events. The locked Learn pill on the Song List sends nothing: no song was chosen, so no song_click. The first entry is the "Learn Mode unlocked!" popup's Claim, which sends the song_click the Learn pill sends (useLearnEntryClick: song_mode: "learn", song_play_type: "home", no song_order — no list row opened it) for twinkle-twinkle-little-star, then Learn Mode's own session events as usual.

  • Learn Mode sends through one tracker, src/features/learn/learn-analytics.ts, made once per visit by useLearnSessionAnalytics. The screen only says when:

    • the action phase;
    • a key press, saying whether it belongs to the final stage's judged run;
    • a stage completed;
    • the final (test) stage's run ended;
    • out of hearts, a revive offered, a revive;
    • a revive about to restart the stage's attempt, with that attempt's counts (carryAttemptCounts), and the time the revive's ad took (excludeAdTime);
    • a stage left (stageLeft, from goToStage);
    • Retry / Restart / Next song;
    • leaving.

    The tracker owns the per-session guards. A Retry, Restart or Next song opens a new song_session_id. The Learn CTA reuses the song's session unless it already has a click or reached song_ap (trackSongClickForNewPlay).

  • Learn me_start has two milestones, and sends once per session on whichever the session reaches first:

    • stage 1 completed; or
    • the 5th press of the final stage's challenge run — the milestone for a session that can never complete stage 1: a Retry, a Replay, or a player returning to a song whose stages they have all passed and resuming on the show.

    The count is the final (test) stage's Challenge only. Its Practice counts nothing, the listen step and the "I'm ready!" card take no play input at all, and neither does any earlier stage. Every press the run takes counts, right or wrong: the milestone is that the player is playing the show, not that they are playing it well. Like every other run-state flag the count is per song session — leaving and coming back, or a Retry / Restart / Next song, starts it again from zero, and me_start still goes out at most once per session. The threshold is LEARN_CHALLENGE_ME_START_PRESSES in src/features/learn/learn-analytics.ts, the one place the rule lives.

  • Learn song_progress adds up every attempt of the stage that a revive (the out-of-hearts card's Keep going) restarted, until the stage completes or the player moves to another stage: error_cnt sums their wrong presses. hint_cnt is 0 or 1: a revive keeps the attempt's Hint reveal, so the attempt that completes the stage counts that Hint once, however many revives it carried through.

  • Learn song_playtime (on song_end and song_result) runs from song_ap and leaves out the time spent in a revive's ad.

  • Learn song_end / song_result go out the moment the final stage's Challenge run ends: when its last note is ruled on — claimed, or its window (±150 ms on the phone's speaker, ±250 ms on headphones) shut with nothing claiming it — not when the backing reaches its cue marker, which on some songs is seconds later. So song_playtime stops at the last note, and a press after it is not judged: it adds nothing to error_cnt (on song_result, and the stage's song_progress) or wrong_rate, and does not count towards me_start's five presses. A run nothing ever rules on is ended by a backstop, 2.5 s after its last window shuts. A run the player backs out of (back after "I'm ready!", then Keep going!) never ends: it sends neither event, and the run that starts over from "I'm ready!" sends them once, with its own stats only, though its song_playtime still runs from song_ap and so includes the abandoned attempt and the time on the Leave card and the question.

  • Learn song_result rates need not sum to 1: perfect_rate + miss_rate is 1, early_rate and late_rate count timed claims again, and wrong_rate counts presses.

  • song_revive_impression goes to subscribers too: the out-of-hearts card offers them Keep going although no ad plays for them. Their heart takes one of the song's 3 refills in any 24 hours, but no ad was watched, so no song_revive follows.

  • The tutorial song (FTUE, on Game Mode's gameplay) sends song_ap once its song is ready to play and is watched for song_quit from there, with Game Mode's chart-group progress (useTutorialSongSession). It has no way out of the song, so only a force quit reports one; its song_end closes the watch.

  • song_quit (src/core/sdk/song-quit.ts) goes out for a session watched from song_ap that is left before song_end / song_result.

    • A quit also ends that song session, so the next play of the song opens a new one.
    • The watch lives in a persisted store (open-song-session-store.ts). A session still open at the next launch was left by a force quit, and flushSongQuitFromLastLaunch in useBootstrapEntrySDK reports it. The flush runs in the bootstrap's mount effect, and the root layout renders no screen until the bootstrap is ready, so it goes out even when the new launch opens onboarding or the tutorial again.
    • progress is "done/total": chart groups in Game Mode and the tutorial song, passed stages in Learn (a five-stage song gives n/5).
    • A Learn visit that ended at its result, or was left before song_ap, releases its session when the screen goes.

Known tracking issues (not fixed yet)

  • song_impression helper exists but no call site wires 2s list visibility yet.
  • Some planned events in event-contract.ts have no trigger — expected until implemented.