v1.0.10 · Release snapshot

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

Google AdMob Ads — Integration Guide

How Magic Piano serves ads through Google AdMob (react-native-google-mobile-ads) behind the in-app @core/ads port (AdsService / AdsNativeAdapter). AdMob replaced IronSource LevelPlay in Phase 1 of the move; Phase 2 added the iOS mediation adapters for ten other networks (§11).


TL;DR — the things that bite

  1. No App ID in Info.plist = crash at launch. The react-native-google-mobile-ads config plugin bakes GADApplicationIdentifier at prebuild from EXPO_PUBLIC_ADMOB_IOS_APP_ID (config/admob-app-id.ts); a missing one fails the prebuild.
  2. Google's demo units only fill under Google's demo App ID. Test-ID mode (EXPO_PUBLIC_ADMOB_USE_TEST_IDS=1) switches both together — the App ID is baked at prebuild, so switching needs expo prebuild + a rebuild, never just a Metro reload. Demo units under the real App ID come back no-fill (Guitar learned this in QC, commit 53e2cdd).
  3. Two units per format. Interstitial, rewarded and App Open keep both High and All loaded at once and take High first at show time (§3); the banner still asks one tier at a time, High before All.
  4. ATT runs before the SDK initialises, and decides only whether the SDK can read the IDFA. No request asks for non-personalised ads (requestNonPersonalizedAdsOnly) because of ATT (§4).
  5. The SDK has one error event for load and show failures. The adapter tells them apart by whether it was asked to show.
  6. Pods are pinned exactly. RNGMA 17.4.0 → Google-Mobile-Ads-SDK 13.10.0 and GoogleUserMessagingPlatform 3.1.0. Every mediation adapter in config/admob-mediation-adapters.ts is pinned too and must accept 13.10.0 (§11).
  7. An adapter does nothing until the dashboard uses it. A network serves only once it sits in the mediation group of the ad unit being asked — set that up for the High and the All unit.
  8. App Open has one unit, All only. EXPO_PUBLIC_ADMOB_IOS_APP_OPEN is in .env; there is no _HIGH, so every load asks the All unit. It sends no analytics, and the rules for when it shows live outside the engine (§6).

Architecture — ports & adapters

Ads live behind @core/ads (clean-architecture port, same pattern as @core/iap). Features and business logic (ads.ts) talk only to AdsService via getAdsService() — never to the SDK.

UI (SongsScreen, PlayScreen, BannerSlot) / ads.ts / app-open.ts
      │  getAdsService().showInterstitial / showRewarded / showAppOpen / preload* / bannerRequest
      ▼
AdsService port  ← src/core/ads/ads-service.ts
      │
      ├─ MediatedAdsService + AdsEngine   (production orchestration: two-tier cache, watchdog,
      │       │                             retries, parking, entitlement gate)
      │       │  AdsNativeAdapter port
      │       ▼
      │  AdMob adapter                     ← src/core/ads/adapters/admob-native-adapter.ts (pure)
      │       │  AdMobSdk port
      │       ▼
      │  admob-sdk.ts → react-native-google-mobile-ads
      │
      └─ SimulateAdsService               (tests — construct + inject into the flow)

<BannerSlot> (screens) ⇢ BannerHost (root, src/components) → AdMobBanner (src/core/ads/adapters/admob-banner.tsx) → BannerAd
  • composition-root.ts reads the unit ids, builds the adapter with ATT + the paid-impression sink, and wires tracking / lifecycle / gate.
  • App Open is driven by AppOpenHost (root layout) through app-open.ts, not by ads.ts: the host says when (after the splash on a cold launch from launch #2; on a background → active switch), the runtime reads the facts and asks the pure rule app-open-policy.ts whether it may show. The engine only loads and shows it. Rules: ad-trigger-logic.md §6.
  • EXPO_PUBLIC_APP_VARIANT=sim swaps in NoAdsAdsService (no SDK at all).
  • Dispose on no-ads: entitlement sync / mid-session premium calls disposeCache().

1. Dependency & versions

// package.json
"dependencies": { "react-native-google-mobile-ads": "17.4.0" }

17.4.0 pins Google-Mobile-Ads-SDK 13.10.0 and UMP 3.1.0 exactly (17.2.0 came with iOS 27 support, 4ab82a74, on GMA 13.6.0; Phase 2 was built on 16.5.0 and GMA 13.5.0). The podspec lets a Podfile override the GMA version with $RNGoogleMobileAdsSDKVersion; nothing needs it. v17 exposes ResponseInfo, so the winning network could be named in ad_source, and it allows the newest Pangle adapter (§11).

2. App ID & test-ID mode

BuildGADApplicationIdentifierUnits requested
NormalEXPO_PUBLIC_ADMOB_IOS_APP_ID (real, ca-app-pub-2489417515168450~2755561396)the env High/All units
EXPO_PUBLIC_ADMOB_USE_TEST_IDS=1Google's demo App ID ca-app-pub-3940256099942544~1458002511Google's demo units, no High

The prebuild refuses a missing real App ID, and refuses Google's demo App ID outside test-ID mode. Android is not shipped yet: its App ID is Google's demo one as a placeholder (the manifest must have one) and no Android unit is configured, so Android never requests an ad.

Test devices. Simulators are test devices automatically, so real units serve test ads there. A real device running a dev build with real units gets REAL ads — register it in AdMob → Settings → Test devices, or build with test-ID mode.

3. Ad units & tiers (High → All)

Env (tracked .env — public client ids):

FormatHighAll
InterstitialEXPO_PUBLIC_ADMOB_IOS_INTERSTITIAL_HIGHEXPO_PUBLIC_ADMOB_IOS_INTERSTITIAL
RewardedEXPO_PUBLIC_ADMOB_IOS_REWARDED_HIGHEXPO_PUBLIC_ADMOB_IOS_REWARDED
App OpenEXPO_PUBLIC_ADMOB_IOS_APP_OPEN_HIGH (optional)EXPO_PUBLIC_ADMOB_IOS_APP_OPEN
BannerEXPO_PUBLIC_ADMOB_IOS_BANNER_HIGHEXPO_PUBLIC_ADMOB_IOS_BANNER

ad-units.ts resolves them: a High that is empty or equal to its All is dropped, and tierOrder() gives the order a load asks them in.

App Open is off while its units are unset (Android: EXPO_PUBLIC_ADMOB_ANDROID_APP_OPEN[_HIGH]). Test-ID mode uses Google's demo App Open unit — iOS ca-app-pub-3940256099942544/5575463023, Android ca-app-pub-3940256099942544/9257395921. It is the engine's third fullscreen format (preloadAppOpen / isAppOpenReady / showAppOpen), on the same tiers, retries, parking and watchdog, but sends no analytics (§8), is not preloaded by start(), and a loaded ad older than 4 h (APP_OPEN_MAX_AGE_MS, app-open-policy.ts) is reloaded instead of shown.

Fullscreen (engine). ads-engine.ts mirrors magicPad's AdMobTierCachePolicy (tier-cache-policy.ts), value for value, so both apps' funnels compare. Each format keeps two tier slots loaded at once — High and All — instead of walking one at a time: preload() asks High, then All after a random 200–500 ms jitter (magicPad's CoPreloadFormat), and once loaded a tier stays in hand. show() (SelectTier) takes High while it holds an ad, else All, else it fails at once — no wait for a load in flight — and asks both again. A failed attempt retries on an unbounded ladder, 5 s → 10 s → 20 s → 40 s → 60 s, the last step repeating for as long as the app stays open; an attempt the SDK never answers within 90 s is written off (load_timeout_90s; magicPad: 60 s) and retried the same way. The tier a show passes over takes a skipped-show count (RecordSuccessfulShow); at 3 in a row its ad is dropped and reloaded (MaybeEvictInterstitialTier), so the cache cannot go stale. The tier that was shown — or failed to show — also reloads itself once the ad is off the screen. Every attempt reports to analytics, retries and all three kinds of reload included: its own *_request, then its own *_request_success or *_request_failed (§8).

Banner. banner-tiers.ts: High's view first; if it does not fill, it is replaced by All's view; if All does not fill either, the view goes away and, after a backoff, the banner retries from High on its own — the same unbounded 5 s → 60 s ladder as the fullscreen formats above, no cycle limit. A filled view is refreshed by the SDK on its own schedule; a failed refresh keeps the ad on screen. Every tier asked reports bannerads_request / _request_success / _request_failed (§8), retries included. Unlike the fullscreen formats, the banner does not keep both tiers warm, but since 2026-10-05 it keeps its one view loaded between screens: react-native-google-mobile-ads can only mount or unmount a <BannerAd>, so the view lives in the root BannerHost (§7) and waits outside the window while no banner screen is open. Outside the window, not transparent: on the simulator (2026-10-05) a transparent banner recorded an impression (PAID) on load and on every 60 s refresh, while one outside the window recorded none and did not refresh until it was shown. A second, hidden tier view is still never kept.

4. ATT, IDFA & personalisation

The ATT prompt still runs before the SDK initialises: requestAttForAds() then preloadAds() at boot (att-flow.ts) — at the end of the onboarding song for a player still in the FTUE funnel — and the engine calls adapter.requestTracking() before init().

ATT decides one thing: whether the SDK can read the IDFA. Every request — interstitial, rewarded, App Open, banner — is the same whatever the answer; none sets requestNonPersonalizedAdsOnly. Until 2026-10-19 every answer but granted asked for non-personalised ads. An iPad QC that day (ATT denied, 18 requests a cell) measured what that flag cost on its own: App Open filled 2/18 with it and 15/18 without; on Interstitial All, networks other than Google won 12/18 with it and 17/18 without, and Meta never won while it was set. Non-personalised ads are a consent question (GDPR in the EEA, the UK and Switzerland), not a tracking one. That is answered by a consent form — Google's UMP, whose IAB TCF signal the SDK and the mediation networks read by themselves — and the app has none yet, like magicPad, which also sends a plain request. A UMP step (form before the tracking prompt, "Privacy options" in Settings) is parked on the local branch feat/ads-ump-consent for when it is wanted.

Nothing else raises the prompt. AppsFlyer starts at every launch and never asks (appsflyer-adapter.ts): its 7.x SDK has no wait-for-ATT option, and asking there put the prompt on a new player's onboarding screen.

5. The adapter — SDK events → port

SDK event (react-native-google-mobile-ads)Port callback
LOADED / RewardedAdEventType.LOADEDonAdLoaded
ERROR before showAd()onAdLoadFailed
ERROR after showAd()onAdDisplayFailed
OPENEDonAdDisplayed
RewardedAdEventType.EARNED_REWARDonAdRewarded
CLOSEDonAdClosed
CLICKEDonAdClicked while showing (openads_click for App Open; the other formats send none)
PAIDanalytics (every full-screen format) + onAdImpression while showing (display confirmation)

Errors arrive namespaced (googleMobileAds/no-fill). show() takes no placement — the engine logs it. The SDK has no destroy for a fullscreen ad; remove() drops the JS listeners.

6. Engine protections

The show-time load grace (RC ads_show_load_grace_ms) is retired along with the RC key itself — the engine never waits at show time any more; §3 has what replaced it. The separate prefetch-on-display buffer is gone too: a shown or failed-to-show tier reloads itself instead. What remains: 8 s display watchdog · close settle deferred until foreground · parking during gameplay · retries with backoff (now the unbounded ladder in §3) · the already-showing guard against a second trigger · the entitlement gate and the QA "Show Ads for Subscriber" toggle. The business caps and flows stay in ads.ts (15 s / 30 s intervals, Flow A / B, pause interstitial, rewarded backfill video) — see ad-trigger-logic.md. App Open's caps (120 s since the last App Open, 60 s since the last interstitial or rewarded) are not in ads.ts either: they live in app-open-policy.ts, fed by the display timestamps ad-lifecycle.ts keeps in memory (see ad-trigger-logic.md §6).

7. Banner — BannerHost and BannerSlot

BannerHost, at the root under the paywall hosts, owns the app's only AdMobBanner (BannerAd, BANNER 320×50).

  • When it loads: once the ads engine has been started by the app's own flow. It never starts the engine, because start() asks for tracking and that prompt waits for the end of the first song.
  • Where it shows: in the most recently opened BannerSlot, which each banner screen renders where its banner sits. The slot reserves 320×50 and reports its window position. The keyboard's slot is open only while the screen is focused.
  • Hidden: with no slot open, the banner stays loaded outside the window, untouchable. The SDK neither counts an impression for it nor refreshes it until it is shown (§3).
  • Rules: in banner-host.pure.ts and banner-host-store.ts.
    • Premium / no-ads players hold no banner.
    • A fullscreen ad hides it, except in the result slots (duringFullscreenLatch).
    • An in-screen popup with a scrim (PopupOverlay — Learn's popups) hides it while open: the popup lives inside the screen tree, under the banner the host draws over every screen.
    • A Game Mode song drops it from the countdown until the engine's melodyEnded (the last note has ended, at least 2.5 s before the result), unless a slot is open: the pause menu asks for its own.
  • Placements: keyboard, sessionResult, fullSongUnlocked, sectionComplete, pause.

8. Analytics

EventSourceNotes
fullads_*, videoads_*engine tracking portan event that stands for one unit names it: ad_unit_tier (high/all) + ad_unit_id — a request and its outcome, a ready, displayed or failed show. *_trigger and videoads_backfill carry none, and so does *_show_notready: it now fires only when neither tier is loaded, so there is never a unit behind it. That empty case is NOT also a failed show — *_show_failed is reserved for an ad that was in hand and did not reach the player, and always names its unit. One *_request → *_request_success / _failed pair per tier a load asks (a High miss + All fill is two pairs; videoads_* has no _request_success) — every attempt reports, retries included; the old tracked/silent split and the separate prefetch buffer are gone, so a reload after a close, a failed show or an eviction reports exactly like a first load
bannerads_show / _empty / _clickBannerHost_show fires when a filled banner is on screen in a slot — it fills there, a slot opens over it, or it refreshes there; once per slot and fill, so the same banner back after a popup or a fullscreen ad is not a new show — with that slot's location, and names the filled unit (ad_unit_tier, ad_unit_id); _empty once per failed High → All cycle (a High miss alone is not empty) or failed refresh
bannerads_request / _request_success / _request_failedBannerHostone pair per tier's view asked, mirroring fullads_request*: ad_unit_tier, ad_unit_id, fail_reason on the failure; fires on every retry too, on the same 5 s → 60 s ladder as the fullscreen formats (§3). location is the open slot's, left out for a load ahead with no slot open
ad_impression, ad_impression_amaPAID eventad_platform=admob, ad_source=admob (see below), ad_unit_name Inter_High / Video_All / Open_All / Banner_High…, ad_unit_tier high/all, currency=USD + value
af_ad_revenue (AppsFlyer)PAID eventmediationNetwork: "google_admob" (react-native-appsflyer's constant — not the hub's googleadmob), monetizationNetwork = ad_source
af_inters_displayed / af_rewarded_displayedPAID event+ ad_unit_tier, currency
  • App Open sends openads_* and its ad_impression / ad_impression_ama (ad_format: "app_open", ad_unit_name: "Open_All") plus AppsFlyer af_ad_revenue. See analytics-events.md for the events and their location.
  • fail_reason (ad-fail-reason.ts), at most 100 characters. What the SDK reported: <code>: <message> with the googleMobileAds/ namespace dropped (no-fill: Request Error: No ad to show.). What the app decides, magicPad's own wording where noted: both_tiers_empty (an interstitial show found neither tier loaded) / show_no_ready (the same, rewarded or App Open) / launch_wait_5s (the cold-launch App Open had nothing loaded after its 5 s wait) — always with no unit, and on *_show_notready only; load_timeout_90s (a load attempt the SDK never answered within 90 s); show_exception: <message> (the show call threw); fullscreen_content_failed (the SDK failed to present and said nothing); display_timeout (the 8 s show watchdog); reward_not_earned (a rewarded the player closed before earning it — *_show_failed only, after *_show). *_show_notready never names a unit or carries any reason but the three above; *_show_failed always names one, and never says no_fill or reports an empty show — the two events answer different questions: was there an ad, and did the ad we had reach the player. Retired: sdk_not_loaded — a tier the SDK quietly dropped is now just not picked, and the reason stays on TierSnapshot.lastError and the ads log, never on a tracked event — and loading, kept only so an old event still has a name for the value it carried before this build (there is no show-time wait left to run out of). RNGMA 16 has no per-network mediation error — that needs ResponseInfo (v17).
  • Ready means a tier holds a loaded ad and the SDK's own loaded flag agrees (NativeAdHandle.isLoaded()).
  • A tracking hook that throws (a dev build rejects invalid event params) is written to the ads log and dropped: it never stalls the load or show it reports on.
  • ad_source: RNGMA 16 does not expose the ad's ResponseInfo, so the filling network is unknown and ad_source reports admob for every impression. v17 exposes it.
  • Currency: AdMob reports revenue in the AdMob account's currency. The ad_impression schema only takes USD, so a non-USD value is sent to Firebase WITHOUT value / currency (never mislabelled, never a dev-time throw) and logged; AppsFlyer gets the real currency and converts it. Keep the AdMob account on USD.
  • Precision (RevenuePrecisions) is logged, not sent — no schema field.
  • If the AdMob app is ever linked to the Firebase project, the SDK also logs Firebase's own automatic ad_impression — check revenue is not counted twice.

9. QA — AdMob Ad Inspector

Dev builds show an ADS TEST pill on the Song List header (AdInspectorButton) → getAdsService().openAdInspector() → MobileAds().openAdInspector(): every ad unit's request log, the mediation waterfall per request, and SDK/adapter status. Release builds never render it. The SDK opens it only on a test device; on a real phone the first tap is refused with error 22, whose message names the phone's test id — admob-sdk.ts registers that id for the session (dev builds only) and opens the inspector on the retry, so from then on the phone is served test ads. Once the mediation groups exist, open an ad unit to see its ad sources and whether each adapter was found, and use Single ad source test to force one network and check that it fills — on a real device, a test device in AdMob.

The engine keeps a 200-line log (getAdsLog() / subscribeAdsLog()). Set EXPO_PUBLIC_ADS_DEBUG=1 in .env.local (restart Metro with -c) to mirror it to the Metro console: [ads:interstitial] LOAD FAILED — tier=high …, retry #1 in 5000ms — tier=high …, LOADED — tier=all …, [ads:paid] rewarded high value=… USD, and so on — the quickest way to watch the tiers work.

10. Info.plist — SKAdNetwork & ATS

  • SKAdNetwork: config/skadnetwork-items.ts — 193 ids, reconciled on 2026-09-21 with the list each mediation network publishes (Google's AdMob partners, AppLovin, Unity Ads, Mintegral, Pangle, Meta, InMobi, Liftoff Monetize, DT Exchange). The former LevelPlay export (173) lacked 20 of InMobi's and DT Exchange's, DT Exchange's own 9g2aggbj52 among them. Moloco publishes none and asks for no manual entry.
  • AdAttributionKit: AdNetworkIdentifiers — Liftoff Monetize's 6 .adattributionkit ids, which it requires alongside SKAdNetworkItems (InMobi's 3 are among them).
  • ATS NSAllowsArbitraryLoads: true, and nothing else. InMobi and DT Exchange ask for plain HTTP, and AppLovin's guide to mediated networks asks for this key alone. Do not add Google's NSAllowsArbitraryLoadsForMedia / …InWebContent: once either is present iOS ignores NSAllowsArbitraryLoads, and this key already allows what they would.
  • Meta on iOS 16 (open): Meta asks apps to call FBAdSettings.setAdvertiserTrackingEnabled before the ads SDK starts, and says iOS 17+ no longer needs it. The app targets 16.4, so Meta demand on iOS 16 devices runs without that signal until a native hook sets it from the ATT answer.

11. Phase 2 — mediation adapters

iOS only (Android ads are not shipped). The adapters are Google-built pods listed in config/admob-mediation-adapters.ts; app.config.ts hands them to expo-build-properties ios.extraPods, and Expo's autolinking adds them to the app target at pod install. No JS talks to them — the Google Mobile Ads SDK loads each adapter by class name when a mediation group asks for its network.

NetworkPod (pinned)BringsLinked as
AppLovinGoogleMobileAdsMediationAppLovin 13.6.4.0AppLovinSDK 13.6.4dynamic framework
BIGO AdsGoogleMobileAdsMediationBigo 6.1.0.0BigoADS 6.1.0not yet checked
BidMachineGoogleMobileAdsMediationBidMachine 3.8.2.0BidMachine 3.8.2not yet checked
DT ExchangeGoogleMobileAdsMediationFyber 8.4.10.0Fyber_Marketplace_SDK 8.4.10static
InMobiGoogleMobileAdsMediationInMobi 11.4.1.0InMobiSDK 11.4.1dynamic framework
IronSourceGoogleMobileAdsMediationIronSource 9.6.0.0.0IronSourceSDK 9.6.0.0static
Liftoff MonetizeGoogleMobileAdsMediationVungle 7.7.7.0VungleAds 7.7.7static
Meta Audience NetworkGoogleMobileAdsMediationFacebook 6.22.0.0FBAudienceNetwork 6.22.0dynamic framework
MintegralGoogleMobileAdsMediationMintegral 8.1.7.0MintegralAdSDK/All 8.1.7static
MolocoGoogleMobileAdsMediationMoloco 4.10.0.0MolocoSDKiOS 4.10.0dynamic framework
PangleGoogleMobileAdsMediationPangle 8.1.1.1.0Ads-Global 8.1.1.1 (incl. its TikTokBusinessSDK subspec)static
Unity AdsGoogleMobileAdsMediationUnity 4.20.1.0UnityAds 4.20.1static

Pins. Every adapter podspec declares the GMA range it accepts; all twelve above say ~> 13.3 (≥ 13.3, < 14), so they sit on RNGMA's 13.10.0. Before bumping one, read the new release's Google-Mobile-Ads-SDK dependency on the CocoaPods trunk — a release that needs a newer GMA fails pod install. Pangle stays on the adapter picked under GMA 13.5.0, when every newer stable one needed ~> 13.6; 13.10.0 now meets that, so it can move up in a change of its own.

BIGO Ads and BidMachine (added 2026-10-19, ahead of their dashboard setup) are bidding partners for every format. Their SKAdNetwork ids are in config/skadnetwork-items.ts; BidMachine's AdAttributionKit ids were already there. Before they can bid, the PO needs, for each network: the Magic Piano iOS app registered (BIGO reviews it before any ad slot can be made), a bidding placement per format (BIGO Slot ID; BidMachine Source ID + Placement ID), the network added as a Bidding ad source to every mediation group — Interstitial, Rewarded and Banner, High and All, and a group for App Open, which has none yet — and its lines in app-ads.txt.

Dead-strip — checked, nothing to change. The SDK looks adapters up by class name, so a Release link that strips them would fail only at runtime. A Release build (2026-09-21) still held all ten GADMediationAdapter* classes then; BIGO Ads' and BidMachine's are unchecked. Re-check after a toolchain or pin change with strings -a MagicPiano.app/MagicPiano | grep '^GADMediationAdapter' (the LevelPlay build needed DEAD_CODE_STRIPPING = NO; these pods do not).

Size. The four dynamic frameworks add about 26 MB to the simulator build; the six static SDKs land in the main binary. Read the real download size per device in App Store Connect.

What only the dashboard can do. An adapter serves nothing until its network sits in the mediation group of the ad unit being asked. Each format needs a group covering both its High and its All unit, with the network's own app / placement ids mapped in AdMob. Until then the SDK's cached config lists only GADMAdapterGoogleAdMobAds for the units, and no adapter initialises.

Keys & where they come from

All AdMob ids are public client ids in the tracked .env — prebuild (App ID) and the bundle (units) read them from the checkout, on CI too (App Open has its All unit only — no _HIGH). They are NOT CI secrets: the ios_internal job in .gitlab-ci.yml fails the build if the job env defines one (a defined variable, even empty, shadows .env) or if .env lacks one, and clears Metro's cache so the bundle re-inlines them.

When a Metro reload is enough vs. a full prebuild

ChangeNeeds
Engine / adapter / banner JS, ad triggersMetro reload
Unit ids in .envMetro restart with a cleared cache (expo start -c) — values are inlined
App ID, test-ID mode, SKAdNetwork, ATT text, RNGMA version, mediation adapter podsexpo prebuild --clean --platform ios + rebuild

References