Loading an Interstitial Ad
The following code shows you how to attach listeners and load the first interstitial:
const INTERSTITIAL_AD_UNIT_ID = Platform.select({ android: 'android_interstitial_ad_unit_ID', ios: 'ios_interstitial_ad_unit_ID', }); const [retryAttempt, setRetryAttempt] = useState(0); const initializeInterstitialAds = () = { AppLovinMAX.addInterstitialLoadedEventListener(() => { // Interstitial ad is ready to show. AppLovinMAX.isInterstitialReady(INTERSTITIAL_AD_UNIT_ID) now returns 'true' // Reset retry attempt setRetryAttempt(0) }); AppLovinMAX.addInterstitialLoadFailedEventListener(() => { // Interstitial ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds) setRetryAttempt(retryAttempt + 1); const retryDelay = Math.pow(2, Math.min(6, retryAttempt)); console.log('Interstitial ad failed to load - retrying in ' + retryDelay + 's'); setTimeout(function() { loadInterstitial(); }, retryDelay * 1000); }); AppLovinMAX.addInterstitialClickedEventListener(() => { ... }); AppLovinMAX.addInterstitialDisplayedEventListener(() => { ... }); AppLovinMAX.addInterstitialAdFailedToDisplayEventListener(() => { // Interstitial ad failed to display. AppLovin recommends that you load the next ad loadInterstitial(); }); AppLovinMAX.addInterstitialHiddenEventListener(() => { loadInterstitial(); }); // Load the first interstitial loadInterstitial(); } const loadInterstitial = () => { AppLovinMAX.loadInterstitial(INTERSTITIAL_AD_UNIT_ID); }
Showing an Interstitial Ad
To show an interstitial ad, call showInterstitial()
:
try { const isInterstitialReady = await AppLovinMAX.isInterstitialReady(interstitial_ad_unit_ID); if (isInterstitialReady) { AppLovinMAX.showInterstitial(interstitial_ad_unit_ID); } } catch(error) { // error handling }