Interstitial integration

Last updated on April 30, 2018

Note: The status bar is hidden during interstitialA full-screen ad displayed in content transitions. For example, a video ad that loads between levels of a mobile game. ads.

Adding an interstitial ad to your app

  1. In your view controller, import the SDK.

  2. Conform your view controller to the OXMAdViewDelegate protocol.

  3. Create a variable to reference OXMAdView and instantiate it.

  4. In your view controller, set parameters in the viewDidLoad method:

    1. Set the adUnitID.
    2. Set the domain.
    3. Assign the delegate and set it to self.
    4. (Recommended) Enrich the request by setting values on the userParameters property.
    5. Set autoDisplayOnLoad to false.
  5. Call load() on the OXMAdView.

  6. Implement the OXMAdViewDelegate methods.

  7. If you want to use flex ads to allow multiple ad sizes for an ad unitThe smallest inventory component that represents the space on a site where ads display., use the flexAdSize parameter. For details, see Flex ads.

  8. Display the interstitial.

Swift code sample


import OpenXSDKCore
 
class MyViewController : UIViewController, OXMAdViewDelegate {
 
	@IBOutlet weak var adView:OXMAdView!
	@IBOutlet weak var showButton:UIButton!
 
	override func viewDidLoad() {
		super.viewDidLoad()
		self.showButton.isEnabled = false
 
		self.adView.adUnitId = "123456789"
		self.adView.domain = "pub-d.openx.net"
		self.adView.delegate = self
		self.adView.flexAdSize = OXMFlexAdSize.Interstitial_1024x768_480x320_300x250
		self.adView.userParameters.userGender = OXMGender.male
		self.adView.userParameters.userAge = 21
		self.adView.autoDisplayOnLoad = false
		self.adView.load()
	}
 
	// MARK: OXMAdViewDelegate
	// Called every time an ad had loaded and is ready for display. If you
	// experience an ad quality issue, you can identify the ad by the
	// transactionId in the adDetails object.
	func adDidLoad(adView:OXMAdView, adDetails:OXMAdDetails) {
		NSLog("OpenX ad loaded: \(adView) Transaction ID = \(adDetails.transactionId)")
				
		// When appropriate, show the interstitial.
		self.adView.showAsInterstitialFromRoot(self)   
	}
 
	// Called whenever the load process fails to produce a viable ad.
	func adDidFailToLoad(adView:OXMAdView, error:Error) {
		NSLog("adDidFailToLoad: \(adView), error: \(error)")
	}
 
	// Called after an ad has rendered to the device's screen.
	func adDidDisplay(adView:OXMAdView) {
		NSLog("adDidDisplay: \(adView)")
	}
 
	// Called once an ad has finished displaying all of its creatives.
	func adDidComplete(adView:OXMAdView) {
		NSLog("adDidComplete: \(adView)")
	}
 
	// Called when the user clicks on an ad and a click-through is
	// about to occur.
	func adWasClicked(adView:OXMAdView) {
		NSLog("adWasClicked: \(adView)")
	}
 
	// Called when the user closes a click-through.
	func adClickthroughDidClose(adView:OXMAdView) {
		NSLog("adClickthroughDidClose: \(adView)")
	}
 
	// Called when an MRAID ad expands.
	func adDidExpand(adView:OXMAdView) {
		NSLog("adDidExpand: \(adView)")
	}
 
	// Called when an MRAID ad collapses.
	func adDidCollapse(adView:OXMAdView) {
		NSLog("adDidCollapse: \(adView)")
	}
 
	// Called when the ad leaves the app.
	func adDidLeaveApplication(adView:OXMAdView) {
		NSLog("adDidLeaveApplication: \(adView)")
	}
 
	// Called when a displayed interstitial, closes by user.
	func adInterstitialDidClose(adView:OXMAdView) {
		NSLog("adInterstitialDidClose: \(adView)")
	}
 
}

Objective-C code sample


// Contents of file: ViewController.h
#import <UIKit/UIKit.h>
#import <OpenXSDKCore/OpenXSDKCore.h>
  
@interface ViewController : UIViewController, OXMAdViewDelegate
  
@property IBOutlet OXMAdView* adView;
@property IBOutlet UIButton* showButton;
  
@end
  
  

 


// Contents of file: ViewController.m
#import "ViewController.h"
 
@interface ViewController ()
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
	[super viewDidLoad];
	[self.showButton setEnabled: NO];
 
	self.adView.adUnitId = @"123456789";
	self.adView.domain = @"pub-d.openx.net";
	self.adView.delegate = self;
	self.adView.flexAdSize = OXMFlexAdSize.Interstitial_1024x768_480x320_300x250;
	self.adView.userParameters.userGender = OXMGenderMale;
	self.adView.userParameters.userAge = 21;
	self.adView.autoDisplayOnLoad = NO;
	[self.adView load];
}
 
#pragma mark OXMAdViewDelegate
// Called every time an ad has loaded and is ready for display. If you
// experience an ad quality issue, you can identify the ad by the transactionId
// in the adDetails object.
- (void)adDidLoad:(nonnull OXMAdView *)adView adDetails:(nonnull OXMAdDetails *)adDetails {
	NSLog(@"Openx ad loaded: %@ with transaction id: %@", adView, adDetails.transactionId);
				
	// When appropriate, show the interstitial.
	[self.adView showAsInterstitialFromRoot:self];
}
 
// Called whenever the load process fails to produce a viable ad.
- (void)adDidFailToLoad:(nonnull OXMAdView *)adView error:(nonnull NSError *)error {
	NSLog(@"adDidFailToLoad: %@, error: %@", adView, error);
}
 
// Called after an ad has rendered to the device's screen.
- (void)adDidDisplay:(nonnull OXMAdView *)adView {
	NSLog(@"adDidDisplay: %@", adView);
}
 
// Called once an ad has finished displaying all of its creatives.
- (void)adDidComplete:(nonnull OXMAdView *)adView {
	NSLog(@"adDidComplete: %@", adView);
}
 
// Called when the user clicks on an ad and a click-through is about to occur.
- (void)adWasClicked:(nonnull OXMAdView *)adView {
	NSLog(@"adWasClicked: %@", adView);
}
 
// Called when the user closes a click-through.
- (void)adClickthroughDidClose:(nonnull OXMAdView *)adView {
	NSLog(@"adClickthroughDidClose: %@", adView);
}
 
// Called when an MRAID ad expands.
- (void)adDidExpand:(OXMAdView * _Nonnull)adView{
	NSLog(@"adDidExpand: %@", adView);
}
 
// Called when an MRAID ad collapses.
- (void)adDidCollapse:(OXMAdView * _Nonnull)adView{
	NSLog(@"adDidCollapse: %@", adView);
}
 
// Called when a displayed interstitial, closes by user.
- (void)adInterstitialDidClose:(nonnull OXMAdView *)adView {
	NSLog(@"adInterstitialDidClose: %@", adView);
}
 
@end