HyBid Android SDK - pre-bid for DFP - Interstitial

Interstitials will be rendered using PublisherInterstitialAd through the HyBidDFPInterstitialCustomEvent adapter.

Requirements

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

    You can find a demo app with code samples for this type of integration here.
    [block:api-header] { "title": "Create PublisherInterstitialAd object" } [/block]
    Create a PublisherInterstitialAd attribute.
    [block:code] { "codes": [ { "code": "private PublisherInterstitialAd mDFPInterstitial;", "language": "java" } ] } [/block]
    Create and initialise the interstitial object.
    [block:code] { "codes": [ { "code": "mDFPInterstitial = new PublisherInterstitialAd(this);\nmDFPInterstitial.setAdUnitId(\"DFP_AD_UNIT_ID\");\nmDFPInterstitial.setAdListener(new AdListener() {\n @Override\n public void onAdLoaded() {\n // Once the interstitial is loaded it should be shown here\n }\n\n @Override\n public void onAdFailedToLoad(int i) {\n \n }\n\n @Override\n public void onAdImpression() {\n \n }\n\n @Override\n public void onAdClicked() {\n \n }\n\n @Override\n public void onAdOpened() {\n \n }\n\n @Override\n public void onAdLeftApplication() {\n \n }\n\n @Override\n public void onAdClosed() {\n \n }\n});", "language": "java" } ] } [/block]

    Code sample

    Create PublisherInterstitialAd object

    private PublisherInterstitialAd mDFPInterstitial;
    mDFPInterstitial = new PublisherInterstitialAd(this);
    mDFPInterstitial.setAdUnitId("DFP_AD_UNIT_ID");
    mDFPInterstitial.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // Once the interstitial is loaded it should be shown here
        }
    
        @Override
        public void onAdFailedToLoad(int i) {
                    
        }
    
        @Override
        public void onAdImpression() {
                    
        }
    
        @Override
        public void onAdClicked() {
                    
        }
    
        @Override
        public void onAdOpened() {
                    
        }
    
        @Override
        public void onAdLeftApplication() {
                    
        }
    
        @Override
        public void onAdClosed() {
                    
        }
    });

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 DFP. 
        }

        @Override
        public void onRequestFail(Throwable throwable) {

        }
    });

    interstitialRequestManager.requestAd();
}

Request ad to DFP

After the ad is successfully received from PubNative, the request should be made to DFP with some parameters that will help the ad be chosen properly in the DFP 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) {
        PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();

        Set<String> keywordSet = HeaderBiddingUtils.getHeaderBiddingKeywordsSet(ad, KeywordMode.TWO_DECIMALS);
        for (String key: keywordSet) {
            builder.addKeyword(key);
        }

        Bundle keywordBundle = HeaderBiddingUtils.getHeaderBiddingKeywordsBundle(ad, KeywordMode.TWO_DECIMALS);
        for (String key: keywordBundle.keySet()) {
            builder.addCustomTargeting(key, keywordBundle.getString(key));
        }

        PublisherAdRequest adRequest = builder.build();
        mDFPInterstitial.loadAd(adRequest);
    }

    @Override
    public void onRequestFail(Throwable throwable) {

    }
});

After making this request to DFP, it will run it's waterfall and if the line item targeted by our keywords gets chosen, the HyBidDFPInterstitialCustomEvent 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.

mDFPInterstitial = new PublisherInterstitialAd(this);
mDFPInterstitial.setAdUnitId("DFP_AD_UNIT_ID");
mDFPInterstitial.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        mDFPInterstitial.show();
    }

    @Override
    public void onAdFailedToLoad(int i) {
                
    }

    @Override
    public void onAdImpression() {
                
    }

    @Override
    public void onAdClicked() {
                
    }

    @Override
    public void onAdOpened() {
                
    }

    @Override
    public void onAdLeftApplication() {
                
    }

    @Override
    public void onAdClosed() {
                
    }
});

Return to the main page