Skip to main content

Quick start

This page shows a banner and an interstitial with Google's sample ad units, which always serve test ads. It assumes you finished installation and native setup.

1. Configure requests​

Call Admob.setRequestConfiguration once, before loading ads, for example after consent is known:

import { Admob } from 'nitro-ui-admob'

Admob.setRequestConfiguration({ maxAdContentRating: 'teen' })

Starting the SDK is optional: the first load() or banner request starts it. Call Admob.initialize() to start it early.

2. Show a banner​

import { Admob, BannerAd } from 'nitro-ui-admob'

function Footer() {
return (
<BannerAd
adUnitId={Admob.testAdUnitId('banner')}
onAdFailedToLoad={(error) => console.warn(error.message)}
/>
)
}

The default size, anchoredAdaptive, takes the full laid-out width and the height the SDK picks. See banner ads.

3. Show an interstitial​

Keep one interstitial loaded with AdPreloader and show it at a natural break:

import { AdPreloader, Admob, InterstitialAd } from 'nitro-ui-admob'

const interstitials = new AdPreloader(() => InterstitialAd.load(Admob.testAdUnitId('interstitial')))
interstitials.start()

function onLevelComplete() {
const ad = interstitials.take()
if (ad === undefined) return // none ready yet
ad.onAdDismissed = () => console.log('dismissed')
ad.show()
}

take() returns undefined until an ad has loaded, and starts loading the next one.

4. Use your own ad units​

Replace Admob.testAdUnitId(...) with the ad unit IDs from the AdMob console before release. Keep test ads on your own devices with testDeviceIds.

Next​