DFP Interstitials - pubnative/pubnative-hybid-android-sdk GitHub Wiki
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.
Create a PublisherInterstitialAd attribute.
private PublisherInterstitialAd mDFPInterstitial;
Create and initialise the interstitial object.
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 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();
}
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() {
}
});