Rewarded interstitial ads

Display full-screen rewarded interstitial ads that reward users without requiring opt-in.

A rewarded interstitial is a full-screen rewarded ad shown at a transition, without asking the user to opt in. If they finish the action, the app grants a reward you set in AdMob. The user can close the ad.

Rewarded interstitial ad shown at a natural transition
Rewarded interstitial ad at a natural transition.

To create a new rewarded interstitial ad, call the createForAdRequest method from the RewardedInterstitialAd class. The first argument of the method is the "Ad Unit ID". For testing, we can use a Test ID, however for production the ID from the Google AdMob dashboard under "Ad units" should be used:

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

const adUnitId = __DEV__
  ? TestIds.REWARDED_INTERSTITIAL
  : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';

const rewardedInterstitial = RewardedInterstitialAd.createForAdRequest(adUnitId, {
  keywords: ['fashion', 'clothing'],
});

The second argument is additional optional request options object to be sent whilst loading an advert, such as keywords & location. Setting additional request options helps AdMob choose better tailored ads from the network. View the RequestOptions source code to see the full range of options available.

The call to createForAdRequest returns an instance of the RewardedInterstitialAd class, which provides a number of utilities for loading and displaying rewarded interstitial ads.

To listen to events, such as when the advert from the network has loaded or when an error occurs, we can subscribe via the addAdEventListener method:

js
import React, { useEffect, useRef, useState } from 'react';
import { Button, Text, View } from 'react-native';
import {
  AdEventType,
  RewardedInterstitialAd,
  RewardedAdEventType,
  TestIds,
} from 'react-native-google-mobile-ads';

const adUnitId = __DEV__
  ? TestIds.REWARDED_INTERSTITIAL
  : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';

const rewardedInterstitial = RewardedInterstitialAd.createForAdRequest(adUnitId, {
  keywords: ['fashion', 'clothing'],
});

// onContinue moves the app on to its next step.
function LevelTransition({ onContinue }) {
  const [loaded, setLoaded] = useState(false);
  const [introVisible, setIntroVisible] = useState(false);
  const onContinueRef = useRef(onContinue);
  onContinueRef.current = onContinue;
  const showPendingRef = useRef(false);

  useEffect(() => {
    const unsubscribeLoaded = rewardedInterstitial.addAdEventListener(
      RewardedAdEventType.LOADED,
      () => {
        setLoaded(true);
      },
    );
    const unsubscribeEarned = rewardedInterstitial.addAdEventListener(
      RewardedAdEventType.EARNED_REWARD,
      reward => {
        console.log('User earned reward of ', reward);
      },
    );
    const unsubscribePaid = rewardedInterstitial.addAdEventListener(AdEventType.PAID, event => {
      console.log('Rewarded interstitial revenue', event.value, event.currency);
    });
    const unsubscribeClosed = rewardedInterstitial.addAdEventListener(AdEventType.CLOSED, () => {
      showPendingRef.current = false;
      setLoaded(false);
      // Preload the next ad on the same instance, then move on.
      rewardedInterstitial.load();
      onContinueRef.current();
    });
    // show() resolves once presentation is handed to the SDK; a later failure arrives here.
    const unsubscribeError = rewardedInterstitial.addAdEventListener(AdEventType.ERROR, error => {
      console.warn(error);
      setLoaded(false);
      if (showPendingRef.current) {
        showPendingRef.current = false;
        onContinueRef.current();
      }
    });

    // Start loading the rewarded interstitial ad straight away
    rewardedInterstitial.load();

    // Unsubscribe from events on unmount
    return () => {
      unsubscribeLoaded();
      unsubscribeEarned();
      unsubscribePaid();
      unsubscribeClosed();
      unsubscribeError();
    };
  }, []);

  if (introVisible) {
    return (
      <View>
        <Text>Watch a short ad to earn 50 coins?</Text>
        <Button
          title="Watch ad"
          onPress={() => {
            if (showPendingRef.current) return;
            setIntroVisible(false);
            showPendingRef.current = true;
            // Not loaded, already showing, or a platform decline reject; a destroyed ad throws.
            rewardedInterstitial.show().catch(error => {
              showPendingRef.current = false;
              console.warn(error);
              onContinue();
            });
          }}
        />
        <Button
          title="Skip"
          onPress={() => {
            setIntroVisible(false);
            onContinue();
          }}
        />
      </View>
    );
  }

  // Without a loaded advert, the transition goes straight to the next step.
  return (
    <Button title="Continue" onPress={() => (loaded ? setIntroVisible(true) : onContinue())} />
  );
}

The code above subscribes to the rewarded interstitial ad events (via addAdEventListener()) and immediately starts to load a new advert from the network (via load()). At the natural transition, pressing "Continue" shows an intro screen that states the reward and offers to skip, but only once an advert has loaded; otherwise the app moves straight on. Only when the user chooses to watch is the show method on the rewarded interstitial ad instance called, showing the advert over-the-top of your application. "Skip", a rejected show, an ERROR event after show() resolved, and the CLOSED event all call onContinue, and the CLOSED listener also loads the next advert on the same instance. The sample assumes EARNED_REWARD arrives before CLOSED; for valuable rewards, confirm the grant with server-side verification.

Like Interstitial Ads, you can listen to the events with the addAdEventListener such as when the user clicks the advert or closes the advert and returns back to your app. However, you can listen to an extra EARNED_REWARD event which is triggered when user completes the advert action. An additional reward payload is sent with the event, containing the amount and type of rewarded (specified via the dashboard).

To learn more, view the RewardedAdEventType source code.

Forward AdEventType.PAID payloads to your revenue telemetry pipeline.

Server-side verification (SSV)

While the EARNED_REWARD event only occurs on the client, Server Side Verification (or SSV) can be used for confirming a user completed an advert action. For this, you have to specify the Server Side Verification callback URL in your Ads dashboard.

You can customize SSV parameters when your SSV callback is called by setting the serverSideVerificationOptions field in your RequestOptions parameter.

js
const rewardedInterstitialAd = RewardedInterstitialAd.createForAdRequest(adUnitId, {
  serverSideVerificationOptions: {
    userId: '9999',
    customData: 'my-custom-data',
  },
});

If you request an Advert as in the example above, AdMob will call your server with the userId and customData fields as shown below:

text
[14/Aug/2020 12:51:43] "GET /views/admob-ssv/?ad_network=...&ad_unit=...&custom_data=my-custom-data&reward_amount=1&reward_item=test_reward_item&timestamp=1597377102267&transaction_id=148cc85...&user_id=9999&signature=MEUCIQCQSi3cQ2PlxlEAkpN...&key_id=3335... HTTP/1.1" 200 0

You still need to verify these incoming requests yourself to ensure they are genuine. To learn more about callback parameters and verifying, see the AdMob SDK Server Side Verification(SSV) documentation.

Caveats / limitations

High-engagement rewarded chrome (close / progress) is owned by Google's AdActivity. See Rewarded ads.