react-native-google-mobile-ads
    Preparing search index...

    Class InterstitialAd

    A class for interacting and showing Interstitial Ads.

    An Interstitial advert can be pre-loaded and shown at a suitable point in your apps flow, such as at the end of a level in a game. An Interstitial is a full screen advert, laid on-top of your entire application which the user can interact with. Interactions are passed back via events which should be handled accordingly inside of your app.

    First create a new Interstitial instance, passing in your Ad Unit ID from the Google Mobile Ads configuration console, and any additional request options. The example below will present a test advert, and only request a non-personalized ad.

    import { InterstitialAd, TestIds } from 'react-native-google-mobile-ads';

    const interstitial = InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL, {
    requestNonPersonalizedAdsOnly: true,
    });

    Each advert needs to be loaded from Google Mobile Ads before being shown. It is recommended this is performed before the user reaches the checkpoint to show the advert, so it's ready to go. Before loading the advert, we need to setup event listeners to listen for updates from Google Mobile Ads, such as advert loaded or failed to load.

    Event types match the AdEventType interface. Once the advert has loaded, we can trigger it to show:

    import { AdEventType } from 'react-native-google-mobile-ads';

    interstitial.addAdEventListener(AdEventType.LOADED, () => {
    interstitial.show().catch(console.warn);
    });

    interstitial.load();

    The advert will be presented to the user, and several more events can be triggered such as the user clicking the advert or closing it.

    Hierarchy (View Summary)

    Index
    • Parameters

      • type: AdType
      • requestId: number
      • adUnitId: string
      • adLoadFunction: AdLoadFunction
      • adShowFunction: AdShowFunction
      • adDestroyFunction: AdDestroyFunction
      • requestOptions: RequestOptions

      Returns InterstitialAd

    • Parameters

      • event: {
            body: {
                data?:
                    | RewardedAdReward & { responseInfo?: ResponseInfo }
                    | AppEvent & { responseInfo?: ResponseInfo }
                    | PaidEvent & { responseInfo?: ResponseInfo }
                    | { responseInfo?: ResponseInfo };
                error?: {
                    code: string;
                    message: string;
                    phase?: "load" | "show";
                    reason?: string;
                    responseInfo?: ResponseInfo;
                    responseInfoJson?: string;
                };
                type: EventType;
            };
        }

      Returns void

    • Listen to ad events. See AdEventTypes for more information.

      Returns an unsubscriber function to stop listening to further events.

      // Create InterstitialAd/RewardedAd
      const advert = InterstitialAd.createForAdRequest('...');

      const unsubscribe = advert.addAdEventListener(AdEventType.LOADED, () => {

      });

      // Sometime later...
      unsubscribe();

      Type Parameters

      Parameters

      • type: T

        The event type, e.g. AdEventType.LOADED.

      • listener: AdEventListener<T>

        A listener callback containing a event type, error and data.

      Returns () => void

    • Listen to ad events. See AdEventTypes for more information.

      Returns an unsubscriber function to stop listening to further events.

      // Create InterstitialAd/RewardedAd
      const advert = InterstitialAd.createForAdRequest('...');

      const unsubscribe = advert.addAdEventsListener(({ type, payload }) => {
      });

      // Sometime later...
      unsubscribe();

      Type Parameters

      Parameters

      • listener: AdEventsListener<T>

        A listener callback containing a event type, error and data.

      Returns () => void

    • Show the loaded advert to the user.

      Uses two error channels:

      • Rejects the returned promise when the show did not happen: the ad has not loaded, a show is already in flight, or the platform declines. Handle these with .catch() (or try { await } catch).
      • Throws synchronously for programmer errors: the ad has been destroyed, or showOptions are structurally invalid (checked only on a loaded ad with no show in flight, so otherwise the rejection comes first). Fix the call site.

      The fullscreen hooks' show absorbs both channels.

      // Create InterstitialAd/RewardedAd
      const advert = InterstitialAd.createForAdRequest('...');

      advert.addAdEventListener(AdEventType.LOADED, () => {
      advert
      .show({
      immersiveModeEnabled: true,
      })
      .catch(console.warn);
      });

      Parameters

      • OptionalshowOptions: AdShowOptions

        An optional AdShowOptions interface.

      Returns Promise<void>

    • Creates a new InterstitialAd instance.

      import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';

      const interstitialAd = InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL, {
      requestAgent: 'CoolAds',
      });

      interstitialAd.addAdEventListener(AdEventType.LOADED, () => {
      interstitialAd.show().catch(console.warn);
      });

      interstitialAd.load();

      Parameters

      • adUnitId: string

        The Ad Unit ID for the Interstitial. You can find this on your Google Mobile Ads dashboard.

      • OptionalrequestOptions: RequestOptions

        Optional RequestOptions used to load the ad.

      Returns InterstitialAd

    _adDestroyFunction: AdDestroyFunction
    _adEventListenerId: number
    _adEventListenersMap: Map<EventType, Map<number, AdEventListener<EventType>>>
    _adEventsListenerId: number
    _adEventsListeners: Map<number, AdEventsListener<EventType>>
    _adLoadFunction: AdLoadFunction
    _adShowFunction: AdShowFunction
    _adUnitId: string
    _destroyed: boolean
    _isLoadCalled: boolean
    _loaded: boolean
    _nativeListener: EmitterSubscription
    _presenceMarked: boolean
    _requestId: number
    _requestOptions: RequestOptions
    _responseInfo: ResponseInfo | null
    _showRequested: boolean
    _type: AdType