Interstitials will be rendered using MoPubInterstitial through the HyBidHeaderBiddingInterstitialCustomEvent adapter.

Requirements:

  • Ad Zone Id from the PubNative Publisher Dashboard
  • MoPub Ad Unit Id for the ad placement that you want to request.

Code sample

You can find a demo app with code samples for this type of integration here.

Create MoPubInterstitial object

Create a MoPubInterstitial attribute.

private MoPubInterstitial mMopubInterstitial;

Create and initialise the interstitial object.

mMopubInterstitial = new MoPubInterstitial(this, "MOPUB_AD_UNIT_ID");
mMopubInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
    @Override
    public void onInterstitialLoaded(MoPubInterstitial interstitial) {
        // Once the interstitial is loaded it should be shown here
    }

    @Override
    public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode  errorCode) {
        
    }

    @Override
    public void onInterstitialShown(MoPubInterstitial interstitial) {
        
    }

    @Override
    public void onInterstitialDismissed(MoPubInterstitial interstitial) {
        
    }

    @Override
    public void onInterstitialClicked(MoPubInterstitial interstitial) {
        
    }
});

Create HyBid Ad Request

Create a RequestManager to handle the request to the ad server.

private void loadInterstitial() {
    RequestManager interstitialRequestManager = new InterstitialRequestManager();
    interstitialRequestManager.setZoneId("ZONE_ID");
    interstitialRequestManager.setRequestListener(new RequestManager.RequestListener() {
        @Override
        public void onRequestSuccess(Ad ad) {
            // Here you will handle the request to MoPub. 
        }

        @Override
        public void onRequestFail(Throwable throwable) {

        }
    });

    interstitialRequestManager.requestAd();
}

Request ad to 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 HeaderBiddingUtils must be used so the SDK can generate the proper keywords for the received ad.

interstitialRequestManager.setRequestListener(new RequestManager.RequestListener() {
    @Override
    public void onRequestSuccess(Ad ad) {
        mMopubInterstitial.setKeywords(HeaderBiddingUtils.getHeaderBiddingKeywords(ad, KeywordMode.TWO_DECIMALS));
        mMopubInterstitial.load();
    }

    @Override
    public void onRequestFail(Throwable throwable) {
        // Request ad to MoPub without adding the pre bid keywords
        mMopubInterstitial.load();
    }
});

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

When the interstitial is loaded, the onInterstitialLoaded method in the InterstitialAdListener will be triggered and it can be used to show the interstitial.

mMopubInterstitial = new MoPubInterstitial(this, "MOPUB_AD_UNIT_ID");
mMopubInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
    @Override
    public void onInterstitialLoaded(MoPubInterstitial interstitial) {
        mMopubInterstitial.show();
    }

    @Override
    public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode  errorCode) {
        
    }

    @Override
    public void onInterstitialShown(MoPubInterstitial interstitial) {
        
    }

    @Override
    public void onInterstitialDismissed(MoPubInterstitial interstitial) {
        
    }

    @Override
    public void onInterstitialClicked(MoPubInterstitial interstitial) {
        
    }
});