Skip to main content
Version: v2.0

Interstitial ads

Prerequisites

Implementation

The main steps to integrate interstitial ads are:

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

Load an ad

Loading an ad is accomplished using the static load(with:request:completionHandler:) (Swift) / loadWithAdUnitID:request:completionHandler: (Objective-C) method on the interstitial-ad class. The load method requires your ad unit ID, an ad-request object, and a completion handler which gets called when ad loading succeeds or fails. The loaded interstitial-ad object is provided as a parameter in the completion handler. The below example shows how to load a Google Ad Manager interstitial ad in your ViewController class.

In the current Google Mobile Ads SDK for iOS (12.x), the Swift API drops the GAM / GAD prefixes: GAMInterstitialAd is exposed in Swift as AdManagerInterstitialAd, and GAMRequest as AdManagerRequest. The Objective-C class names continue to use the GAM prefix.
import GoogleMobileAds
import UIKit

class ViewController: UIViewController {

private var premiumAdsInterstitial: AdManagerInterstitialAd?

override func viewDidLoad() {
super.viewDidLoad()
Task {
do {
premiumAdsInterstitial = try await AdManagerInterstitialAd.load(
with: "/361045431/example/interstitial",
request: AdManagerRequest())
} catch {
print("Failed to load interstitial ad with error: \(error.localizedDescription)")
}
}
}
}
For testing during development against AdMob you can use Google's sample interstitial ad unit ID ca-app-pub-3940256099942544/4411468910. For Google Ad Manager testing, see Google's Ad Manager sample ad units.

Register for callbacks

In order to receive notifications for presentation events, you must implement the full-screen content delegate protocol (FullScreenContentDelegate in Swift, GADFullScreenContentDelegate in Objective-C) and assign it to the fullScreenContentDelegate property of the returned ad. The 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:

class ViewController: UIViewController, FullScreenContentDelegate {

private var premiumAdsInterstitial: AdManagerInterstitialAd?

override func viewDidLoad() {
super.viewDidLoad()
Task {
do {
premiumAdsInterstitial = try await AdManagerInterstitialAd.load(
with: "/6499/example/interstitial",
request: AdManagerRequest())
premiumAdsInterstitial?.fullScreenContentDelegate = self
} catch {
print("Failed to load interstitial ad with error: \(error.localizedDescription)")
}
}
}

/// Tells the delegate that the ad failed to present full screen content.
func ad(_ ad: FullScreenPresentingAd, 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: FullScreenPresentingAd) {
print("Ad will present full screen content.")
}

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

The interstitial-ad object is a one-time-use object. This means that once an interstitial ad is shown, it cannot be shown again. A best practice is to load another interstitial ad in the adDidDismissFullScreenContent callback so that the next interstitial ad starts loading as soon as the previous one is dismissed.

Display the ad

Interstitials should be displayed during natural pauses in the flow of an app. Between levels of a game or after the user completes a task are good examples. Here's an example of how to do this in one of the action methods in a UIViewController:

@IBAction func doSomething(_ sender: Any) {
guard let interstitial = premiumAdsInterstitial else {
print("Ad wasn't ready")
return
}
interstitial.present(from: self)
}

Some best practices

Consider whether interstitial ads are the right type of ad for your app.

Interstitial ads work best in apps with natural transition points. The conclusion of a task within an app, like sharing an image or completing a game level, creates such a point. Because the user is expecting a break in the action, it's easy to present an interstitial ad without disrupting their experience. Make sure you consider at which points in your app's workflow you'll display interstitial ads and how the user is likely to respond.

Remember to pause the action when displaying an interstitial ad.

There are a number of different types of interstitial ads: text, image, video, and more. It's important to make sure that when your app displays an interstitial ad, it also suspends its use of some resources to allow the ad to take advantage of them. For example, when you make the call to display an interstitial ad, be sure to pause any audio output being produced by your app. You can resume playing sounds in the adDidDismissFullScreenContent: event handler, which will be invoked when the user has finished interacting with the ad. In addition, consider temporarily halting any intense computation tasks (such as a game loop) while the ad is being displayed. This will ensure that the user doesn't experience slow or unresponsive graphics or stuttered video.

Allow for adequate loading time.

Just as it's important to make sure you display interstitial ads at an appropriate time, it's also important to make sure the user doesn't have to wait for them to load. Loading the ad in advance by calling load() before you intend to call show() can ensure that your app has a fully loaded interstitial ad at the ready when the time comes to display one.

Don't flood the user with ads.

While increasing the frequency of interstitial ads in your app might seem like a great way to increase revenue, it can also degrade the user experience and lower clickthrough rates. Make sure that users aren't too frequently interrupted that they're no longer able to enjoy using your app.

Don't use the load completion callback to show the interstitial.

This can cause poor user experience. Instead, pre-load the ad before you need to show it. Then check canPresent(fromRootViewController:) (Swift) / canPresentFromRootViewController:error: (Objective-C) on the interstitial-ad to find out if it is ready to be shown.