Interstitial ads are full-screen ads that appear at transition points in your app, such as between screens or during the pause between levels in a game. Your users can tap the ad to visit the destination, or close the ad and return to the app. For details, see Interstitial ad guidance and a case study.
This guide shows you how to integrate interstitial ads into a React Native app.
Prerequisites
- Set up Google Mobile Ads SDK for React Native.
- Enable test ads and use the following test ad unit ID:
Android
ca-app-pub-3940256099942544/1033173712
iOS
ca-app-pub-3940256099942544/4411468910
Load an ad
To load an interstitial ad, call the load
method on the InterstitialAd class.
The following example loads an interstitial ad on success and logs an error on failure:
export async function loadInterstitialAd(
adUnitId: string,
): Promise<InterstitialAd | null> {
try {
const ad = await InterstitialAd.load({adUnitId});
return ad;
} catch (error) {
const loadError = error as LoadAdError;
console.error('Failed to load interstitial ad:', loadError.message);
return null;
}
}
Listen for ad events
Before you show the ad, set the
adEventCallback listener on the
loaded InterstitialAd instance. This listener
receives callbacks for ad lifecycle events, such as the ad showing on the
screen or a user tapping the ad. For available callbacks, see
AdEventCallback.
The following example sets callbacks to listen for ad events:
export function registerAdEvents(ad: InterstitialAd) {
ad.adEventCallback = {
// Called when the ad is presented on screen.
onAdShowedFullScreenContent: () => {
console.log('Interstitial ad showed full screen content.');
},
// Called when the ad is closed by the user.
onAdDismissedFullScreenContent: () => {
console.log('Interstitial ad dismissed full screen content.');
ad.destroy();
},
// Called when presentation fails.
onAdFailedToShowFullScreenContent: (error) => {
console.error('Failed to show interstitial ad:', error);
ad.destroy();
},
// Called when an impression is recorded.
onAdImpression: () => {
console.log('Interstitial ad recorded an impression.');
},
// Called when the user taps the ad.
onAdClicked: () => {
console.log('Interstitial ad was clicked.');
},
// Called when the ad is estimated to have earned money.
onAdPaid: (adValue) => {
console.log(
`Interstitial ad paid: ${adValue.amountMicros}` +
` ${adValue.currencyCode}`,
);
},
};
}
This example also calls the destroy method when a user closes the
ad or when the ad fails to show. This process releases the resources the ad
used.
Show the ad
To show an interstitial ad, call the show
method on the loaded InterstitialAd instance.
The following example shows an interstitial ad:
export function showInterstitialAd(ad: InterstitialAd) {
ad.show();
}
View the full example
This section covers the full example to integrate an interstitial ad into a React Native app.
The following example integrates the ad into a React Native component, manages the ad instance in state, and provides controls to load and display the ad:
Next steps
After you integrate interstitial ads, explore the following topics: