Google Mobile Ads SDK

DoubleClick for Publishers (DFP) Interstitial Ads

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.

The richer, more immersive nature of these ads makes them more expensive and subject to impression constraints.

Create an interstitial ad unit in DFP

Create an ad unit in DFP to represent the interstitial ad unit. Interstitial ad units can be defined with one of the four common sizes, regardless of the actual screen size of individual devices. The SDK will handle rendering the creative correctly on screens which are of slightly different sizes.

  • Phones: 320x480 (portrait), 480x320 (landscape)
  • Tablets: 768x1024 (portrait), 1024x768 (landscape)

There is no need to define a separate ad unit for landscape mode. You can simply add the landscape size (e.g. 480x320 for smartphones) to line items targeting the interstitial ad unit and include a creative with the landscape size in addition to the regular portrait size.

Android (Google Play)

PublisherInterstitialAd

The richer, more heavyweight nature of PublisherInterstitialAd 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 PublisherAdView:

  • Import com.google.android.gms.ads.doubleclick.*
  • Declare the instance
  • Create it, specifying a DFP 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.doubleclick.*;

public class InterstitialExample extends Activity {

  private PublisherInterstitialAd interstitial;

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

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

    // Create ad request.
    PublisherAdRequest adRequest = new PublisherAdRequest.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 an example project containing a sample interstitial.

Android (6.4.1 and earlier SDKs)

DFPInterstitialAd

The richer, more heavyweight nature of DFPInterstitialAd 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 DfpAdView:

  • Import com.google.ads.* and com.google.ads.doubleclick.*
  • Declare the instance
  • Create it, specifying a DFP 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.*;
import com.google.ads.doubleclick.*;

public class BannerExample extends Activity implements AdListener {

  private DfpInterstitialAd interstitial;

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

    // Create the interstitial
    interstitial = new DfpInterstitialAd(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(). 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.

Download an example project containing a sample interstitial.

iOS

DFPInterstitial

The richer, more heavyweight nature of DFPInterstitial 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 DFPBannerView:

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

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

// InterstitialExampleViewController.h

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

@interface InterstitialExampleViewController : UIViewController {
 // Declare one as an instance variable
 DFPInterstitial *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_ = [[DFPInterstitial 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.

Tip: DFPInterstitial 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 {

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

GADInterstitialDelegate

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

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

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

interstitial_.delegate = self;
- (void)interstitialDidReceiveAd:(DFPInterstitial *)interstitial
Sent when loadRequest: has succeeded and the interstitial isReady for display at the appropriate moment.
- (void)interstitial:(DFPInterstitial *)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:(DFPInterstitial *)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:(DFPInterstitial *)interstitial
Sent when the user has dismissed interstitial and it has left the screen.
- (void)interstitialWillDismissScreen:(DFPInterstitial *)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:(DFPInterstitial *)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 DFPInterstitial.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 an example project containing a sample interstitial.

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.