Interstitial Placements
Interstitial Ads are full screen ads that display over an application’s content. These ads often result in higher eCPM for developers. The best time to use Interstitial Ads is during a natural break in the application flow, such as after completion of a level in a game. Within interstitial ad placements, developers have the option to display interactive video ads. These units often produce the highest eCPM. To ensure a placement is able to receive these ads, speak to a Yahoo Account Manager.
Integrating Interstitial Placements
To add an interstitial placement to an app, import the required classes, create an interstitial ad, load the ad, and then show the ad once it has finished loading.
The following steps illustrate the process:
1. Import the required classes
Import the following into the Android activity or iOS view controller that will trigger the interstitial ad.
//Required Yahoo Mobile SDK imports for interstitial ads
import com.yahoo.ads.ErrorInfo;
import com.yahoo.ads.interstitialplacement.InterstitialAd;
import com.yahoo.ads.interstitialplacement.InterstitialPlacementConfig;
//Required Yahoo Mobile SDK imports for interstitial ads
import com.yahoo.ads.ErrorInfo
import com.yahoo.ads.interstitialplacement.InterstitialAd
import com.yahoo.ads.interstitialplacement.InterstitialPlacementConfig
//Required Yahoo Mobile SDK imports for interstitial ads
#import <YahooAds/YahooAds.h>
//Required Yahoo Mobile SDK imports for interstitial ads
import YahooAds
2. Create an interstitial ad placement configuration
An instance of the interstitial placement config is required to load an ad. The config is created once, typically when the app’s activity or view controller is created.
// Create placement config required to load the ad
InterstitialPlacementConfig interstitialPlacementConfig = new InterstitialPlacementConfig(PLACEMENT_ID, null);
// Create placement config required to load the ad
val placementConfig = InterstitialPlacementConfig(PLACEMENT_ID, null)
// Create placement config required to load the ad
YASInterstitialPlacementConfig *interstitialConfig = [[YASInterstitialPlacementConfig alloc] initWithPlacementId:placementID requestMetadata:nil];
// Create placement config required to load the ad
let interstitialConfig = YASInterstitialPlacementConfig(placementId: placementID,
requestMetadata: nil)
3. Load and show an ad
Create an instance of an InterstitialAd, then load, and show the ad. After the ad is loaded, it can be shown. Be sure to do so at an appropriate time as interstitial ads take over the entire screen.
// Instantiate InterstitialAd and Listen for Interstitial Ad callbacks
InterstitialAd interstitialAd = new InterstitialAd(context, PLACEMENT_ID, interstitialAdListener);
runOnUiThread(() -> {
// Load the ad
interstitialAd.load(interstitialPlacementConfig);
});
// Instantiate InterstitialAd and Listen for Interstitial Ad callbacks
val interstitialAd = InterstitialAd(context, PLACEMENT_ID, interstitialAdListener)
runOnUiThread {
// Load the ad
interstitialAd.load(interstitialPlacementConfig)
}
// Instantiate a YASInterstitialAd
YASInterstitialAd *interstitialAd = [[YASInterstitialAd alloc] initWithPlacementId:placementID];
// Retain the ad object
self.interstitialAd = interstitialAd;
// Listen for interstitial ad callbacks
interstitialAd.delegate = self;
// Load the ad
[self.interstitialAd loadWithPlacementConfig:interstitialConfig];
// Instantiate a YASInterstitialAd
let interstitialAd = YASInterstitialAd(placementId: placementID)
// Retain the ad object
self.interstitialAd = interstitialAd
// Listen for interstitial ad callbacks
self.interstitialAd.delegate = self
// Load the ad
self.interstitialAd.load(with: interstitialConfig)
Interstitial ad callbacks
The Interstitial ad callbacks convey changes in the state of the ad. For example, callbacks are provided for ad loaded, ad load failed, ad display, clicks, failure, etc. Please refer to the API documentation for Android and iOS for complete list of available callbacks.
//Interstitial ad callbacks
@Override
public void onLoaded(final InterstitialAd interstitialAd) {
// Show the ad
runOnUiThread(() -> {
interstitialAd.show(context);
}
}
@Override
void onLoadFailed(final InterstitialAd interstitialAd, final ErrorInfo errorInfo) {
// Handle load error
Log.e(TAG, errorInfo.toString());
});
@Override
public void onClicked(final InterstitialAd interstitialAd) {
Log.i(TAG, "Interstitial ad clicked");
}
//etc...
//Interstitial ad callbacks
override fun onLoaded(interstitialAd: InterstitialAd) {
// Show the ad
runOnUiThread {
interstitialAd.show(context)
}
}
override fun onLoadFailed(interstitialAd: InterstitialAd, errorInfo: ErrorInfo) {
// Handle load error
Log.e(TAG, errorInfo.toString())
}
override fun onClicked(interstitialAd: InterstitialAd) {
Log.i(TAG, "Interstitial ad clicked")
}
//etc...
//Interstitial ad callbacks
- (void)interstitialAdDidLoad:(YASInterstitialAd *)interstitialAd
{
// Show the ad
dispatch_async(dispatch_get_main_queue(), ^{
[interstitialAd showFromViewController:self];
}
}
- (void)interstitialAdLoadDidFail:(YASInterstitialAd *)interstitialAd withError:(YASErrorInfo *)errorInfo
{
// Handle load error
NSLog(@"Interstitial ad load did fail: %@", errorInfo);
}
- (void)interstitialAdClicked:(YASInterstitialAd *)interstitialAd
{
NSLog(@"Interstitial ad was clicked");
}
// etc...
//Interstitial ad callbacks
func interstitialAdDidLoad(_ interstitialAd: YASInterstitialAd) {
// Show the ad
DispatchQueue.main.async {
interstitialAd.show(from: self)
}
}
func interstitialAdLoadDidFail(_ interstitialAd: YASInterstitialAd, withError errorInfo: YASErrorInfo) {
// Handle load error
print("Interstitial ad load did fail: \(errorInfo)")
}
func interstitialAdClicked(_ interstitialAd: YASInterstitialAd) {
print("Interstitial ad was clicked")
}
//etc...
4. Android Only - Destroy the ad
When the ad instance is no longer needed or when the activity is finished, the instance must be destroyed to free up resources.
//Destroy the ad
interstitialAd.destroy();
//Destroy the ad
interstitialAd?.destroy()
Next Steps
- If you were able to successfully load an ad, congratulations! That was pretty easy wasn’t it.
- If you would like a complete example of implementing an Interstitial Ad within an app, please review the sample application.
- If you are still having trouble, please contact your account manager.