-
Notifications
You must be signed in to change notification settings - Fork 1
MoPub Leaderboard Banners
Rectangle Banners will be rendered using MoPubView through the HyBidHeaderBiddingLeaderboardCustomEvent adapter.
Requirements:
- Ad Zone Id from the PubNative Publisher Dashboard
- MoPub 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 MoPub view inside your layout file.
<com.mopub.mobileads.MoPubView
android:id="@+id/mopub_leaderboard"
android:layout_width="728dp"
android:layout_height="90dp" />
Create a MoPubView attribute to hold the reference to the UI element.
private MoPubView mMopubLeaderboard;
Get a reference to it from your code.
mMopubLeaderboard = findViewById(R.id.mopub_leaderboard);
mMopubLeaderboard.setBannerAdListener(new MoPubView.BannerAdListener() {
@Override
public void onBannerLoaded(MoPubView banner) {
}
@Override
public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {
}
@Override
public void onBannerClicked(MoPubView banner) {
}
@Override
public void onBannerExpanded(MoPubView banner) {
}
@Override
public void onBannerCollapsed(MoPubView banner) {
}
});
mMopubLeaderboard.setAutorefreshEnabled(false);
Create a RequestManager to handle the request to the ad server.
private void loadLeaderboard() {
RequestManager mLeaderboardRequestManager = new LeaderboardRequestManager();
mLeaderboardRequestManager.setZoneId("ZONE_ID");
mLeaderboardRequestManager.setRequestListener(new RequestManager.RequestListener() {
@Override
public void onRequestSuccess(Ad ad) {
// Here you will handle the request to MoPub.
}
@Override
public void onRequestFail(Throwable throwable) {
}
});
mLeaderboardRequestManager.requestAd();
}
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.
mLeaderboardRequestManager.setRequestListener(new RequestManager.RequestListener() {
@Override
public void onRequestSuccess(Ad ad) {
mMopubLeaderboard.setAdUnitId("MOPUB_AD_UNIT_ID");
mMopubLeaderboard.setKeywords(HeaderBiddingUtils.getHeaderBiddingKeywords(ad, KeywordMode.TWO_DECIMALS));
mMopubLeaderboard.loadAd();
}
@Override
public void onRequestFail(Throwable throwable) {
// Request ad to MoPub without adding the pre bid keywords
mMopubLeaderboard.setAdUnitId("MOPUB_AD_UNIT_ID");
mMopubLeaderboard.loadAd();
}
});
After making this request to MoPub, it will run it's waterfall and if the line item targeted by our keywords gets chosen, the HyBidHeaderBiddingLeaderboardCustomEvent adapter will be called to render the ad.
Project setup
Displaying ads using HyBid
Displaying Ads with Header Bidding with GAM (DFP)
Mediation
Unity Mediation
Misc