You are here: Developers > OpenX Mobile iOS SDK > Interstitial ad integration

Interstitial integration

Last updated on October 5, 2017

Note: If you are using Interface Builder to assist with your ad integration, set up OXMAdView in Interface Builder before following the steps below. Also be aware that 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) Set the interstitial's display properties. The default close position is the top right.
    5. (Recommended) Enrich the request by setting values such as userGender, userAnnualIncomeInUS, and userAge on the userParameters property.
    6. 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. (Recommended) Define a close button. The close button image appears on the top-right corner of the interstitial ad, allowing the user to close the ad.

    Note: The demo app contains close button images. You can also use custom close images as well.

Swift code sample


import OpenXSDKCore

class MyViewController : UIViewController, OXMAdViewDelegate {

	@IBOutlet weak var adView:OXMAdView!
	@IBOutlet weak var showButton:UIButton!
	override func 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.interstitialDisplayProperties.closeButtonText = ""
		self.adView.interstitialDisplayProperties.closeButtonImage = UIImage(named: "interstitialCloseButton")
		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)")
	}

	// Called whenever the load process fails to produce a viable ad.
	func adDidFailToLoad(_ adView:OXMAdView, error:NSError) {
		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 a user has closed an interstitial.
	func adInterstitialDidClose(_ adView:OXMAdView) {
		NSLog("adInterstitialDidClose: \(adView)")
	}

	//MARK: Show Button
	@IBAction func showButtonClicked() {
		self.adView.showAsInterstitialFromRoot(self)
	}

}

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.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.interstitialDisplayProperties.closeButtonText = @"";
	self.adView.interstitialDisplayProperties.closeButtonImage = [UIImage imageNamed: @"interstitialCloseButton"];
	self.adView.autoDisplayOnLoad = NO;
	[self.adView load];
}

#pragma 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.
- (void)adDidLoad:(OXMAdView * _Nonnull)adView adDetails:(OXMAdDetails * _Nonnull)adDetails {
	NSLog(@"Openx ad loaded: %@ with transaction id: %@", adView, adDetails.transactionId);
}

// Called whenever the load process fails to produce a viable ad.
- (void)adDidFailToLoad:(OXMAdView * _Nonnull)adView error:(NSError * _Nonnull)error {
	NSLog(@"adDidFailToLoad: %@, error: %@", adView, error);
}

// Called after an ad has rendered to the device's screen.
- (void)adDidDisplay:(OXMAdView * _Nonnull)adView {
	NSLog(@"adDidDisplay: %@", adView);
}

// Called once an ad has finished displaying all of its creatives.
- (void)adDidComplete:(OXMAdView * _Nonnull)adView {
	NSLog(@"adDidComplete: %@", adView);
}

// Called when the user clicks on an ad and a click-through is about
// to occur.
- (void)adWasClicked:(OXMAdView * _Nonnull)adView {
	NSLog(@"adWasClicked: %@", adView);
}

// Called when the user closes a click-through.
- (void)adClickthroughDidClose:(OXMAdView * _Nonnull)adView {
	NSLog(@"adClickthroughDidClose: %@", adView);
}

#pragma mark - Show Button
- (void) showButtonClicked {
	[self.adView showAsInterstitialFromRoot:self];
}
@end

Feedback form