Rewarded interstitial

Rewarded interstitial is a type of incentivized ad format that allows you offer rewards for ads that appear automatically during natural app transitions. Unlike rewarded ads, users aren't required to opt-in to view a rewarded interstitial.

Prerequisites

  • Google Mobile Ads SDK 7.60.0 or higher.
  • Follow the Get Started guide to import the Google Mobile Ads SDK.
  • Reach out to your account manager to get access to rewarded interstitial.

Implementation

The main steps to integrate rewarded interstitial ads are:

  1. Load an ad.
  2. Register for callbacks.
  3. Display the ad and handle the reward event.

Load an ad

Loading an ad is accomplished using the static loadWithAdUnitID:request:completionHandler: method on the GADRewardedInterstitialAd class. The load method requires your ad unit ID, a GAMRequest object, and a completion handler which gets called when ad loading succeeds or fails. The loaded GADRewardedInterstitialAd object is provided as a parameter in the completion handler. The below example shows how to load a GADRewardedInterstitialAd in your ViewController class.

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController {

  private var rewardedInterstitialAd: GADRewardedInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()

    GADRewardedInterstitialAd.load(withAdUnitID:"/21775744923/example/rewarded_interstitial",
    request: GAMRequest()) { ad, error in
      if let error = error {
        return print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
      }

      self.rewardedInterstitialAd = ad
    }
  }
}

Objective-C

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic, strong) GADRewardedInterstitialAd* rewardedInterstitialAd;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  [GADRewardedInterstitialAd
       loadWithAdUnitID:@"/21775744923/example/rewarded_interstitial"
                request:[GAMRequest request]
      completionHandler:^(
          GADRewardedInterstitialAd* _Nullable rewardedInterstitialAd,
          NSError* _Nullable error) {
        if (!error) {
          self.rewardedInterstitialAd = rewardedInterstitialAd;
        }
      }
  ];
}

Register for callbacks

In order to receive notifications for presentation events, you must implement the GADFullScreenContentDelegate protocol and assign it to the fullScreenContentDelegate property of the returned ad. The GADFullScreenContentDelegate protocol handles callbacks for when the ad presents successfully or unsuccessfully, and when it is dismissed. The following code shows how to implement the protocol and assign it to the ad:

Swift

class ViewController: UIViewController {

  private var rewardedInterstitialAd: GADRewardedInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()

    GADRewardedInterstitialAd.load(withAdUnitID:"/21775744923/example/rewarded_interstitial",
    request: GAMRequest()) { ad, error in
      if let error = error {
        return print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
      }

      self.rewardedInterstitialAd = ad
      self.rewardedInterstitialAd?.fullScreenContentDelegate = self
    }
  }
}

extension ViewController: GADFullScreenContentDelegate {

  /// Tells the delegate that the ad failed to present full screen content.
  func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
    print("Ad did fail to present full screen content.")
  }

  /// Tells the delegate that the ad will present full screen content.
  func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad will present full screen content.")
  }

  /// Tells the delegate that the ad dismissed full screen content.
  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad did dismiss full screen content.")
  }
}

Objective-C

@interface ViewController ()<GADFullScreenContentDelegate>
@property(nonatomic, strong) GADRewardedInterstitialAd *rewardedInterstitialAd;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.

  [GADRewardedInterstitialAd
       loadWithAdUnitID:@"/21775744923/example/rewarded_interstitial"
                request:[GAMRequest request]
      completionHandler:^(
          GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd,
          NSError *_Nullable error) {
        if (!error) {
          self.rewardedInterstitialAd = rewardedInterstitialAd;
          self.rewardedInterstitialAd.fullScreenContentDelegate = self;
        }
      }];
}

/// Tells the delegate that the ad failed to present full screen content.
- (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
    NSLog(@"Ad did fail to present full screen content.");
}

/// Tells the delegate that the ad will present full screen content.
- (void)adWillPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {

    NSLog(@"Ad will present full screen content.");
}

/// Tells the delegate that the ad dismissed full screen content.
- (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
   NSLog(@"Ad did dismiss full screen content.");
}

Display the ad and handle the reward event

When presenting your ad, you must provide a GADUserDidEarnRewardHandler object to handle the reward for the user.

The following code presents the best method for displaying a rewarded interstitial ad.

Swift

func show() {
  guard let rewardedInterstitialAd = rewardedInterstitialAd else {
    return print("Ad wasn't ready.")
  }

  rewardedInterstitialAd.present(fromRootViewController: self) {
    let reward = rewardedInterstitialAd.adReward
    // TODO: Reward the user!
  }
}

Objective-C

- (void)show {
  [_rewardedInterstitialAd presentFromRootViewController:self
                                userDidEarnRewardHandler:^{

                                  GADAdReward *reward =
                                      self.rewardedInterstitialAd.adReward;
                                  // TODO: Reward the user!
                                }];
}