Documentation comes from this release commit, without inheriting newer content. Commit: 371ee4692c.
Interstitial Ads — Logic xuất hiện (review)
Tổng hợp khi nào Interstitial hiện để PO/dev check. Nguồn: code
src/core/sdk/ads.ts,ad-flow.ts, các call-site + ad-trigger-logic.md. SDK path:getAdsService()from@core/ads(business gating vẫn ởads.ts). Cập nhật khi đổi logic.
🚩 Đang dùng Flow nào? → Flow A (default)
ad-flow.ts:activeFlowmặc định =AD_FLOW_A.- RC key
fs_logicquyết định (0 = Flow A, 1 = Flow B); schema default = 0 (src/core/config/rc-contract.tslà nguồn duy nhất cho tên key / kiểu / mô tả). - Feed qua
remote-config.store.ts→setAdFlow(config.fs_logic)khi RC apply. - ⇒ Trừ khi PO đặt
fs_logic = 1trên Firebase Remote Config console, app chạy Flow A. - (Xác nhận từ log device: interstitial
select_songcó bắn → chỉ Flow A mới bắn cái này.)
Đổi sang Flow B: set
fs_logic = 1trên Firebase RC console (template:docs/firebase-remote-config.template.json, sinh bằngbun run rc:template).
⛔ Luật chung (mọi placement, cả 2 flow): inter đầu tiên sau song_end thứ 2
User chỉ gặp interstitial đầu tiên sau khi đã có 2 song_end trong đời app: tutorial là
bài 1, bài user tự chọn đầu tiên là bài 2. Trước đó mọi placement (select_song, song_result,
pause, free_home, song_end, result_home, Learn result) đều bị bỏ qua, và SDK không được gọi.
- Ví dụ PO báo (Flow A): xong tutorial → không nhận bài free → Home → bấm Play bài free →
không dính
select_song. Cósong_endthứ 2 rồi thì các luật cũ mới chạy. - Learn chỉ bắn
song_endkhi lượt Challenge của chặng cuối kết thúc. Learn Mode khoá cho tới khi đủ 4song_end(tutorial tính; xem features/songs.md), nên khi user vào được Learn thì ngưỡngsong_endthứ 2 đã qua từ lâu. - Ở Flow B, ad
song_endcủa bài 2 hiện được luôn:fireSongEndđếm trước khi màn Result gọi ad. - Số đếm =
accumulated_countcủa eventsong_end(getLifetimeEventCount("song_end"), lưu MMKV, mất khi xoá app). Gate ởmaybeShowInterstitial+canShowFreeModeInterstitial(src/core/sdk/ads.ts) khi slice chưa boot; sau đó làfs.first_after_song_endcủa arm (mặc định 2).
Cơ chế A/B — 2 flow loại trừ nhau
Màn hình chỉ báo hành động (reportAdAction, ad-actions.ts); bộ quyết định chọn thời điểm theo Flow A/B: bảng dưới đây khi slice chưa boot, policy của arm sau khi boot (xem ad-trigger-logic.md). Flow A và Flow B không bao giờ chạy cùng lúc.
🅰️ Flow A — USER ACTION (fs_logic = 0, đang active)
Interstitial bắn khi user bấm:
🅱️ Flow B — SONG_END (fs_logic = 1, variant — đang TẮT)
Interstitial bắn khi bài kết thúc:
Ở Flow B: Replay / Next / recommendation KHÔNG ad; select_song / song_result / pause tắt.
Cả 2 flow (orthogonal)
| free_home | Rời tab Keyboard (free mode) → Home / Songs | KeyboardScreen |
song_end của Learn Mode (Flow B)
| song_end (Learn Mode) | Hoàn thành run challenge của stage cuối — run xong khi nốt cuối được chấm (bấm trúng, hoặc hết cửa sổ (±150ms với loa điện thoại, ±250ms với tai nghe) mà không ai bấm), không chờ nhạc chạy tới cue marker → board đứng 3.5s: nhạc chơi tiếp 2s sau nốt cuối rồi fade 1.5s về im lặng (RUN_ENDING_MS), rồi result panel lên và ad hiện đè lên nó (1 lần/run; panel vẽ trước khi xin ad nên đóng ad là thấy result; count-up + nút bấm chờ ad xong). Không có ad (subscriber / remove-ads): panel cũng chờ hết 3.5s đó rồi mới lên | LearnModeScreen (useLearnResultInterstitial) |
Learn result Replay / Next: Flow A chạy song_result rồi waitForFullscreenAdDismissed trước khi clear panel / mount count-in / replace route (giống PlayResultScreen.launchPlay). Flow B skip (đã có song_end). Song list: Flow A song_result+wait; Flow B result_home.
⚙️ Gating — interstitial chỉ hiện khi TẤT CẢ đúng
Khi slice chưa boot, thứ tự kiểm tra trong ads.ts maybeShowInterstitial (sau khi boot là policy của arm: ConfigFullscreenLogic + FsSpacing, các field fs.* của mon_pkg):
- Không phải subscriber — premium / no-ads → skip (không ad).
- Placement đang bật —
ads.shouldShow(placement). - ≥ 15s kể từ interstitial gần nhất —
interstitialIntervalMs(global frequency-cap). - ≥ 30s kể từ rewarded gần nhất —
rewardedToInterstitialIntervalMs(1 chiều: rewarded KHÔNG bị gate, chỉ ghi timestamp). - (chỉ
pause) Σ play-time cộng dồn > 10s —playTimeThresholdS. Reset = 0 khi ad thực sự hiện. - (chỉ
result_home, Flow B) song_count ≥ 2 —resultHomeSongCountThreshold.
Nếu qua hết gate nhưng SDK không có ad (no-fill 509) → outcome unavailable.
🎛️ Remote Config keys (default)
⚠️ Interstitial ≠ Rewarded (đừng nhầm)
- Interstitial = ad ép ở các điểm trên (forced).
- Rewarded = user chủ động xem để unlock bài locked-ads (
unlock_song). Rewarded KHÔNG bị gate 15s/30s. - Modal / video backfill (✅ PO chốt): Rewarded-unlock và interstitial no-fill hiện Skia video backfill (CDN fallback). Video + đồng hồ 15s pause khi app background, resume khi foreground. Thanh progress theo video; nút sound toggle (góc trái, mặc định bật tiếng); nút Close (góc phải) xuất hiện sau 15s foreground watch. RC key
video_ads_backfill_url. Analytics:videoads_backfill/fullads_backfill.
Ngoài scope
- App-Open ads: ✅ code, tách khỏi interstitial (format AdMob riêng, luật riêng, event
openads_*như Guitar — xem analytics-events.md). Từsong_endtrọn đời ≥ 4 (4 bài chơi xong, cộng dồn): hiện sau splash ở lần mở thứ 2+ (trước paywall mở app, chờ nạp tối đa 5s) và khi quay lại từ background trên màn menu (chỉ khi đã nạp sẵn). Cách ≥ 120s App Open trước và ≥ 60s interstitial / rewarded gần nhất; App Open không dời mốc 15s của interstitial. Chi tiết: ad-trigger-logic.md §6. - Banner: top tab Keyboard, subscriber ẩn.
- No fill (
googleMobileAds/no-fill): inventory / tài khoản AdMob (unit mới chưa có fill, app chưa duyệt), không phải code — xem Ad Inspector (admob-integration.md).