Google Mobile Ads SDK

Interstitials

Banners are small ads that when touched typically take the user to some form of full-screen in-app browsing experience.

Interstitials, on the other hand, immediately present rich HTML5 experiences or "web apps" at natural app transition points such as launch, video pre-roll or game level load. Web apps are in-app browsing experiences with a simple close button rather than any navigation bar—the content provides its own internal navigation scheme. Interstitial ads are typically more expensive and subject to impression constraints.

Android (Google Play)

InterstitialAd

The more heavyweight nature of InterstitialAd is reflected by its definition not as a View but rather an Object requiring more distinct instantiation, load and display steps.

Usage is nevertheless very similar to AdView:

  • Import com.google.android.gms.ads.*
  • Declare the instance
  • Create it, specifying an AdMob Ad Unit ID distinct from any used for banners

Once again, the easiest place to do this is somewhere in your app's Activity.

import com.google.android.gms.ads.*;

public class BannerExample extends Activity {

  private InterstitialAd interstitial;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create the interstitial.
    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId(MY_AD_UNIT_ID);

    // Create ad request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Begin loading your interstitial.
    interstitial.loadAd(adRequest);

  }

  // Invoke displayInterstitial() when you are ready to display an interstitial.
  public void displayInterstitial() {
    if (interstitial.isLoaded()) {
      interstitial.show();
    }
  }
}

Here an interstitial is requested as soon as the activity starts. We will then call displayInterstitial() when we're ready to display the interstitial. This method calls show() to show the interstitial after checking isLoaded() to confirm the interstitial has finished loading.

Once shown, the interstitial takes over the screen until the user dismisses it, at which point control returns to your app.

Download the example project.

Android (6.4.1 and earlier SDKs)

InterstitialAd

The richer, more heavyweight nature of InterstitialAd is reflected by its definition not as a View but rather an Object requiring more distinct instantiation, load and display steps.

Usage is nevertheless very similar to AdView:

  • Import com.google.ads.*
  • Declare the instance
  • Create it, specifying an ad unit ID distinct from any used for banners

Once again, the easiest place to do this is somewhere in your app's Activity.

import com.google.ads.*;

public class BannerExample extends Activity implements AdListener {

  private InterstitialAd interstitial;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create the interstitial
    interstitial = new InterstitialAd(this, MY_INTERSTITIAL_UNIT_ID);

    // Create ad request
    AdRequest adRequest = new AdRequest();

    // Begin loading your interstitial
    interstitial.loadAd(adRequest);

    // Set Ad Listener to use the callbacks below
    interstitial.setAdListener(this);
  }

  @Override
  public void onReceiveAd(Ad ad) {
    Log.d("OK", "Received ad");
    if (ad == interstitial) {
      interstitial.show();
    }
  }
}

Here we implement AdListener and immediately show the interstitial upon callbacks to onReceiveAd(). See the Intermediate guide for further details on using AdListener. Alternatively, you can hold onto the interstitial until you're ready to display it, checking with isReady().

Once shown, the interstitial takes over the screen until the user dismisses it, at which point control returns to your app.

Note: The timeout for an interstitial ad request is five seconds. This timeout pertains to the socket connection with the server, and has no relations to the display duration of the interstitial ad.

Download the example project.

iOS

GADInterstitial

The richer, more heavyweight nature of GADInterstitial is reflected by its definition not as a UIView but rather an NSObject requiring more distinct instantiation, load and display steps.

Usage is nevertheless very similar to GADBannerView:

  • Import GADInterstitial.h
  • Declare a GADInterstitial instance in your app's UIViewController
  • Create it
  • Set the ad unit ID

Once again, the best place to do this is in your app's UIViewController.

// InterstitialExampleViewController.h

// Import GADInterstitial's definition from the SDK
#import "GADInterstitial.h"

@interface InterstitialExampleViewController : UIViewController {
 // Declare one as an instance variable
 GADInterstitial *interstitial_;
}

@end

The following performs interstitial setup in the view controller's viewDidLoad initialization hook.

// InterstitialExampleViewController.m

#import "InterstitialExampleViewController.h"

@implementation MyInterstitialHostingViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  interstitial_ = [[GADInterstitial alloc] init];
  interstitial_.adUnitID = MY_INTERSTITIAL_UNIT_ID;
  [interstitial_ loadRequest:[GADRequest request]];
}

@end

You may invoke loadRequest: at any time, however, you must wait for GADInterstitialDelegate's interstitialDidReceiveAd: to be called before displaying the creative. If you encounter GADInterstitialDelegate's interstitial:didFailToReceiveAdWithError: instead, gracefully handle the failure condition.

Note: The timeout for an interstitial ad request is five seconds. This timeout pertains to the socket connection with the server, and has no relations to the display duration of the interstitial ad.

Tip: GADInterstitial is a one-time-use object. It will gracefully fail by calling didFailToReceiveAdWithError: on any requests to load or display an interstitial after the first request.

Once load succeeds the full-screen ad is ready for presentation:

[interstitial_ presentFromRootViewController:self];

The interstitial then takes over the screen until the user dismisses it, at which point control returns to your app and the view controller passed to this method.

Splash Interstitials

One special interstitial use case is a "splash" at app launch.

Invoking loadAndDisplayRequest:usingWindow:initialImage: from within the app delegate's application:didFinishLaunchingWithOptions: effectively queues an interstitial for display the moment it isReady. The initial image—typically the app's default—remains onscreen until the load request either succeeds or fails.

- (BOOL)application:(UIApplication *)application
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  GADInterstitial *splashInterstitial_ = [[GADInterstitial alloc] init];
  splashInterstitial_.adUnitID = MY_INTERSTITIAL_UNIT_ID;
  [splashInterstitial_ loadAndDisplayRequest:[GADRequest request]
                                 usingWindow:window_
                                initialImage:[UIImage imageNamed:@"Default.png"]];
}

If you're mediating interstitial ads with other networks, we recommend you implement this behavior yourself using loadRequest on GADInterstitial.

GADInterstitialDelegate

As with GADBannerViewDelegate, the developer may optionally track interstitial lifecycle events by implementing all or part of GADInterstitialDelegate.

@protocol GADInterstitialDelegate 
  @optional
    - (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial;
    - (void)interstitial:(GADInterstitial *)interstitial
        didFailToReceiveAdWithError:(GADRequestError *)error;
    - (void)interstitialWillPresentScreen:(GADInterstitial *)interstitial;
    - (void)interstitialWillDismissScreen:(GADInterstitial *)interstitial;
    - (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial;
    - (void)interstitialWillLeaveApplication:(GADInterstitial *)interstitial;
@end

Remember to set the delegate before making the request for an ad:

interstitial_.delegate = self;
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
Sent when loadRequest: has succeeded and the interstitial isReady for display at the appropriate moment.
- (void)interstitial:(GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error
Sent when loadRequest: has failed, typically because of network failure, an application configuration error or lack of interstitial inventory, a more common occurrence than with banners. You may wish to log these events for debugging.
- (void)interstitialWillPresentScreen:(GADInterstitial *)interstitial
Sent immediately before interstitial is shown to the user. At this point you should pause any animations, timers or other activities that assume user interaction and save app state, much like on UIApplicationDidEnterBackgroundNotification. Remember that the user may press Home or touch links to other apps like App Store or iTunes within the interstitial, leaving your app.
- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial
Sent when the user has dismissed interstitial and it has left the screen.
- (void)interstitialWillDismissScreen:(GADInterstitial *)interstitial
Sent immediately before interstitial leaves the screen, restoring your app and, in the non-splash case, your root view controller. At this point you should restart any foreground activities paused as part of interstitialWillPresentScreen:
- (void)interstitialWillLeaveApplication:(GADInterstitial *)interstitial
Sent just before your app is backgrounded or terminated as a result of the user touching links to other apps links within interstitial. The normal UIApplicationDelegate notifications like applicationDidEnterBackground: will arrive immediately before this.

During these methods you may consult GADBannerView.hasAutoRefreshed to determine if a refresh triggered the event.

Once again, if you implement your delegate as a distinct object you should be sure to set delegate to nil before releasing the interstitial.

Download the example project.

Windows Phone 8

The InterstitialAd is defined not as a UserControl but rather an object requiring more distinct instantiation, load, and display steps. This is because on its own it doesn't have any visuals associated with it, but rather causes a page to navigate to a full-screen ad.

Usage is nevertheless very similar to AdView:

  • Use the using GoogleAds directive to make it easier to qualify an identifier to a namespace.
  • Declare the instance.
  • Create it, specifying an AdMob ad unit ID distinct from any used for banners.
using GoogleAds;

namespace BannerExample
{
  public partial class MainPage : PhoneApplicationPage
  {
    private InterstitialAd interstitialAd;
    // Constructor
    public MainPage()
    {
      InitializeComponent();
      interstitialAd = new InterstitialAd("MY_AD_UNIT_ID");
      AdRequest adRequest = new AdRequest();

      interstitialAd.ReceivedAd += OnAdReceived;
      interstitialAd.LoadAd(adRequest);
    }

    private void OnAdReceived(object sender, AdEventArgs e)
    {
      System.Diagnostics.Debug.WriteLine("Ad received successfully");
      interstitialAd.ShowAd();
    }
  }
}

You may invoke LoadAd at any time, however, you must wait for InterstitialAd's ReceivedAd event to be raised before displaying the creative. If the FailedToReceiveAd event is raised, gracefully handle the error condition.

Once the ad is received, you can show the ad using the ShowAd method. The interstitial then takes over the screen until the user dismisses it, at which point control returns to your app.

Download the example project.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.