Interstitial Ads

Loading an Interstitial Ad

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

var INTER_AD_UNIT_ID;
if ('IOS' === window.cordova.platformId.toUpperCase()) {
  INTER_AD_UNIT_ID = 'ios_inter_ad_unit_ID';
} else {
  // Assume Android
  INTER_AD_UNIT_ID = 'android_inter_ad_unit_ID';
}

var retryAttempt = 0;

function initializeInterstitialAds()
{
  window.addEventListener('OnInterstitialLoadedEvent', function (adInfo) {
    // Interstitial ad is ready to show. AppLovinMAX.isInterstitialReady(INTER_AD_UNIT_ID) now returns 'true'.
    // Reset retry attempt
    retryAttempt = 0;
  });

  window.addEventListener('OnInterstitialLoadFailedEvent', function (adInfo) {
    // 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++;
    var retryDelay = Math.pow(2, Math.min(6, retryAttempt));

    console.log('Interstitial ad failed to load - retrying in ' + retryDelay + 's');

    setTimeout(function() {
      loadInterstitial();
    }, retryDelay * 1000);
  });

  window.addEventListener('OnInterstitialClickedEvent', function (adInfo) {});
  window.addEventListener('OnInterstitialDisplayedEvent', function (adInfo) {});
  window.addEventListener('OnInterstitialAdFailedToDisplayEvent', function (adInfo) {
    // Interstitial ad failed to display. AppLovin recommends that you load the next ad.
    loadInterstitial();
  });
  window.addEventListener('OnInterstitialHiddenEvent', function (adInfo) {
    loadInterstitial();
  });

  // Load the first interstitial.
  loadInterstitial();
}

function loadInterstitial()
{
  AppLovinMAX.loadInterstitial(INTER_AD_UNIT_ID);
}

Showing an Interstitial Ad

To show an interstitial ad, call showInterstitial():

if (AppLovinMAX.isInterstitialReady(INTER_AD_UNIT_ID))
{
  AppLovinMAX.showInterstitial(INTER_AD_UNIT_ID);
}