Skip to content

MoPub Interstitial Ads

Can Soykarafakılı edited this page May 16, 2018 · 12 revisions

Interstitial Ads will be rendered using MPInterstitialAdController through the PNLiteMoPubInterstitialCustomEvent adapter.

Requirements

  • Ad Zone ID from the PubNative Publisher Dashboard
  • MoPub Ad Unit ID for the Ad Placement that you want to request.

Create MoPub Interstitial

  1. Declare a MPInterstitialAdController *moPubInterstitial property.

Swift:

var moPubInterstitial = MPInterstitialAdController()

Objective-C:

@property (nonatomic, strong) MPInterstitialAdController *moPubInterstitial;
  1. Instantiate the property that you have declared, passing in your MoPub Ad Unit ID.

Swift:

self.moPubInterstitial = MPInterstitialAdController.init(forAdUnitId: <YOUR MoPUB AD UNIT ID HERE>)

Objective-C:

self.moPubInterstitial = [MPInterstitialAdController interstitialAdControllerForAdUnitId:<YOUR MoPUB AD UNIT ID HERE>];
  1. Register your view controller as the moPubInterstitial's delegate (MPInterstitialAdControllerDelegate).

Swift:

self.moPubInterstitial.delegate = self

Objective-C:

self.moPubInterstitial.delegate = self;

For more information about MoPub Interstitial integration, you can refer to the MoPub Documentation as well.

Create PN Lite Ad Request

  1. Import PubnativeLite into your class.

Swift:

import PubnativeLite

Objective-C:

#import <PubnativeLite/PubnativeLite.h>
  1. Declare a PNLiteInterstitialAdRequest *interstitialAdRequest property.

Swift:

var interstitialAdRequest =  PNLiteInterstitialAdRequest()

Objective-C:

@property (nonatomic, strong) PNLiteInterstitialAdRequest *interstitialAdRequest;
  1. Instantiate the property that you have declared. After this, you can request an Ad by, passing your Ad Zone ID and also your registered view controller as the interstitialAdRequest's delegate (PNLiteAdRequestDelegate).

Swift:

self.interstitialAdRequest.requestAd(with: self, withZoneID: <YOUR AD ZONE ID HERE>)

Objective-C:

self.interstitialAdRequest = [[PNLiteInterstitialAdRequest alloc] init];
[self.interstitialAdRequest requestAdWithDelegate:self withZoneID:<YOUR AD ZONE ID HERE>];

Request Ad from MoPub

After the ad is successfully received from PubNative, the request should be made to MoPub with some parameters that will help the ad be chosen properly in the MoPub waterfall.

The PNLitePrebidUtils must be used so that the SDK can generate the proper keywords for the received ad.

Swift:

extension ViewController : PNLiteAdRequestDelegate
{
    func requestDidStart(_ request: PNLiteAdRequest!)
    {
        print("Request\(request) started")   
    }
    
    func request(_ request: PNLiteAdRequest!, didLoadWith ad: PNLiteAd!)
    {
        print("Request loaded with ad: \(ad)")
    if (request == interstitialAdRequest) {
        self.moPubInterstitial.keywords = PNLitePrebidUtils.createPrebidKeywordsString(with: ad, withZoneID: <YOUR AD ZONE ID HERE>)
        self.moPubInterstitial.loadAd()
        }
    }
    
    func request(_ request: PNLiteAdRequest!, didFailWithError error: Error!)
    {
        print("Request\(request) failed with error: \(error.localizedDescription)")
        self.moPubInterstitial.loadAd()  
    }
}

Objective-C:

#pragma mark - PNLiteAdRequestDelegate

- (void)requestDidStart:(PNLiteAdRequest *)request
{
    NSLog(@"Request %@ started:",request);
}

- (void)request:(PNLiteAdRequest *)request didLoadWithAd:(PNLiteAd *)ad
{
    NSLog(@"Request loaded with ad: %@",ad);

     if (request == self.interstitialAdRequest) {
    [self.moPubInterstitial setKeywords:[PNLitePrebidUtils createPrebidKeywordsStringWithAd:ad withZoneID:<YOUR AD ZONE ID HERE>]];
    [self.moPubInterstitial loadAd];
    }
}

- (void)request:(PNLiteAdRequest *)request didFailWithError:(NSError *)error
{
    NSLog(@"Request %@ failed with error: %@",request,error.localizedDescription);
    [self.moPubInterstitial loadAd];
}

After making this request to MoPub, it will run its waterfall and if the line item targeted by our keywords gets chosen, the PNLiteMoPubInterstitialCustomEvent adapter will be called to render the ad.

If the ad is ready to be shown, call showFromViewController: on the interstitial, passing in your view controller.

Swift:

extension ViewController : MPInterstitialAdControllerDelegate
{
    func interstitialDidLoadAd(_ interstitial: MPInterstitialAdController!)
    {
        self.moPubInterstitial.show(from: self)
    }
}

Objective-C:

#pragma mark - MPInterstitialAdControllerDelegate

- (void)interstitialDidLoadAd:(MPInterstitialAdController *)interstitial
{
    NSLog(@"interstitialDidLoadAd");
    [self.moPubInterstitial showFromViewController:self];
}

<- MRect Ads

Home

Installations & Configurations

Displaying Ads with HyBid

Displaying Ads with Header Bidding with GAM

Mediation

Advanced Setup

Integration Checklists for Publishers

Misc

Clone this wiki locally