Interstitial Ads

Loading an Interstitial Ad

The following code shows you how to attach listeners and load the first interstitial:

import { InterstitialAd } from 'react-native-applovin-max';

const INTERSTITIAL_AD_UNIT_ID = Platform.select({
  android: 'android_interstitial_ad_unit_ID',
  ios: 'ios_interstitial_ad_unit_ID',
});

const retryAttempt = useRef(0);

const initializeInterstitialAds = () => {
  InterstitialAd.addAdLoadedEventListener((adInfo: AdInfo) => {
    // Interstitial ad is ready to show. InterstitialAd.isReady(INTERSTITIAL_AD_UNIT_ID) now returns 'true'

    // Reset retry attempt
    retryAttempt.current = 0;
  });
  InterstitialAd.addAdLoadFailedEventListener((errorInfo: AdLoadFailedInfo) => {
    // Interstitial ad failed to load 
    // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
        
    retryAttempt.current += 1;

    const retryDelay = Math.pow(2, Math.min(6, retryAttempt.current));

    console.log('Interstitial ad failed to load - retrying in ' + retryDelay + 's');
        
    setTimeout(function() {
      loadInterstitial();
    }, retryDelay * 1000);
  });
  InterstitialAd.addAdClickedEventListener((adInfo: AdInfo) => { ... });
  InterstitialAd.addAdDisplayedEventListener((adInfo: AdInfo) => { ... });
  InterstitialAd.addAdFailedToDisplayEventListener((adInfo: AdDisplayFailedInfo) = {
    // Interstitial ad failed to display. AppLovin recommends that you load the next ad
    loadInterstitial();
  });
  InterstitialAd.addAdHiddenEventListener((adInfo: AdInfo) => {
    loadInterstitial();
  });

  // Load the first interstitial
  loadInterstitial();
}

const loadInterstitial = () => {
  InterstitialAd.loadAd(INTERSTITIAL_AD_UNIT_ID);
}

Showing an Interstitial Ad

Show an interstitial ad by calling showAd():

const isInterstitialReady = await InterstitialAd.isAdReady(interstitial_ad_unit_ID);
if (isInterstitialReady) {
  InterstitialAd.showAd(interstitial_ad_unit_ID);
}