Enabling interstitial ads

Warning.

This is an archived version of the documentation. Actual documentation for all platforms can be found here.

An interstitial ad is a configurable full-screen ad that reacts to clicks.

Creating and displaying InterstitialAd

  1. Add the import:

    import 'package:yandex_mobileads/mobile_ads.dart';
    Copied to clipboard
  2. Create an object of the InterstitialAd class. You can only use the asynchronous method to create the object:

    final ad = await InterstitialAd.create(
      adUnitId: 'R-M-XXXXXX-Y',
      onAdLoaded: () { 
         /* Do something */
      },
      onAdFailedToLoad: (error) { 
         /* Do something */
     },
    );
    Copied to clipboard
  3. After you create and configure the InterstitialAd class object, load the ads. To load an ad, use the load method that accepts an optional AdRequest object.

    await ad.load(adRequest: AdRequest());
    Copied to clipboard

    You can wait for your ad to load asynchronously using the await keyword. If there's an error, the onAdFailedToLoad method is called to terminate waiting.

  4. Interstitial ads are loaded in the background immediately after the load method is called. To display an interstitial ad, call the show method:

    await ad.show();
    Copied to clipboard

    You can wait for the ad to start displaying asynchronously.

  5. Alternatively, you can use the waitForDismiss asynchronous method to wait until the end of ad serving:

    await ad.waitForDismiss();
    Copied to clipboard

Example of working with interstitial ads

The code demonstrates how to create and configure an InterstitialAd object, and how to load and display an interstitial ad:

Future<void> showInterstitialAd() async {
  final ad = await InterstitialAd.create(
    adUnitId: 'demo-interstitial-yandex',
    onAdLoaded: () { 
        /* Do something */
    },
    onAdFailedToLoad: (error) { 
        /* Do something */
    },
  );
  await ad.load(adRequest: AdRequest());
  await ad.show();
  await ad.waitForDismiss();
}
Copied to clipboard

If an ad is integrated this way, the ad unit appears when showInterstitialAd is called.

To see how the ad will be displayed in the app, use a demo AdUnitId:
  • demo-interstitial-yandex