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
- No App ID in Info.plist = crash at launch. The react-native-google-mobile-ads config
plugin bakes
GADApplicationIdentifierat prebuild fromEXPO_PUBLIC_ADMOB_IOS_APP_ID(config/admob-app-id.ts); a missing one fails the prebuild. - 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 needsexpo prebuild+ a rebuild, never just a Metro reload. Demo units under the real App ID come back no-fill (Guitar learned this in QC, commit53e2cdd). - 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.
- 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). - The SDK has one
errorevent for load and show failures. The adapter tells them apart by whether it was asked to show. - Pods are pinned exactly. RNGMA 17.4.0 →
Google-Mobile-Ads-SDK13.10.0 andGoogleUserMessagingPlatform3.1.0. Every mediation adapter inconfig/admob-mediation-adapters.tsis pinned too and must accept 13.10.0 (§11). - 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.
- App Open has one unit, All only.
EXPO_PUBLIC_ADMOB_IOS_APP_OPENis 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.
composition-root.tsreads 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) throughapp-open.ts, not byads.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 ruleapp-open-policy.tswhether it may show. The engine only loads and shows it. Rules: ad-trigger-logic.md §6. EXPO_PUBLIC_APP_VARIANT=simswaps inNoAdsAdsService(no SDK at all).- Dispose on no-ads: entitlement sync / mid-session premium calls
disposeCache().
1. Dependency & versions
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
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):
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
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.tsandbanner-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
- App Open sends
openads_*and itsad_impression/ad_impression_ama(ad_format: "app_open",ad_unit_name: "Open_All") plus AppsFlyeraf_ad_revenue. See analytics-events.md for the events and theirlocation. fail_reason(ad-fail-reason.ts), at most 100 characters. What the SDK reported:<code>: <message>with thegoogleMobileAds/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_notreadyonly;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_failedonly, after*_show).*_show_notreadynever names a unit or carries any reason but the three above;*_show_failedalways names one, and never saysno_fillor 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 onTierSnapshot.lastErrorand the ads log, never on a tracked event — andloading, 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 needsResponseInfo(v17).- Ready means a tier holds a loaded ad and the SDK's own
loadedflag 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'sResponseInfo, so the filling network is unknown andad_sourcereportsadmobfor every impression. v17 exposes it.- Currency: AdMob reports revenue in the AdMob account's currency. The
ad_impressionschema only takesUSD, so a non-USD value is sent to Firebase WITHOUTvalue/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 own9g2aggbj52among them. Moloco publishes none and asks for no manual entry. - AdAttributionKit:
AdNetworkIdentifiers— Liftoff Monetize's 6.adattributionkitids, which it requires alongsideSKAdNetworkItems(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'sNSAllowsArbitraryLoadsForMedia/…InWebContent: once either is present iOS ignoresNSAllowsArbitraryLoads, and this key already allows what they would. - Meta on iOS 16 (open): Meta asks apps to call
FBAdSettings.setAdvertiserTrackingEnabledbefore 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.
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
References
- react-native-google-mobile-ads: https://docs.page/invertase/react-native-google-mobile-ads
- AdMob iOS — impression-level ad revenue: https://developers.google.com/admob/ios/impression-level-ad-revenue
- AdMob iOS — Ad Inspector: https://developers.google.com/admob/ios/ad-inspector
- AdMob mediation adapters (iOS): https://developers.google.com/admob/ios/choose-networks