The integration of Prebid Rendering API with MoPub assumes that publisher has an account on MoPub and has already integrated the MoPub SDK into the app.
If you do not have MoPub SDK in the app yet, refer the MoPub’s Documentation.
The integration of Prebid Rendering API into MoPub monetization flow is based on MoPub’s Mediation feature.
Steps 1-2 Prebid SDK makes a bid request. Prebid server runs an auction and returns the winning bid to the SDK.
Step 3 Prebid SDK via MoPubAdapters framework sets up targeting keywords into the MoPub’s ad unit.
Step 4 MoPub SDK makes an ad request. MoPub adds the prebid’s line item into the mediation chain.
Step 5 If Prebid’s creative win the waterfall then the MoPub SDK will instantiate respective Prebid Adapter which will render the winning bid. For more details about Mediation and Adapters read the MoPub’s Documentation.
Step 6 The winner is displayed in the app with the respective rendering engine.
Prebid Mediation API supports these ad kinds:
They can be integrated using these API categories.
Integration example:
// 1. Create an AdView
banner = MPAdView(adUnitId: MOPUB_AD_UNIT_ID)
banner.delegate = self
// 2. Create an In-App Bidding Ad Unit
adUnit = MediationBannerAdUnit( configID: CONFIG_ID,
size: adSize,
mediationDelegate: MoPubMediationDelegate())
// 3. Run an Header Bidding auction on Prebid
adUnit.fetchDemand(with: banner!) { [weak self] result in
// 4. Load an Ad
self?.banner.loadAd()
}
Follow the MoPub Instructions for Banner integration.
Create the MediationBannerAdUnit
object with parameters:
configID
- an ID of Stored Impression on the Prebid serversize
- the size of the ad unit which will be used in the bid requestmediationDelegate
- the object from the MoPubAdapters framework responsible for managing MoPub’s ad objects.Call the method fetchDemand()
which performs several actions:
mediationDelegate
When the bid request is completed, the responsibility of making the Ad Request is passed to the publisher. You have to invoke loadAd()
on the MoPub’s Ad View explicitly in the completion handler of the fetchDemand()
.
If the Prebid bid wins on MoPub it will be rendered by PrebidBannerAdapter
. You shouldn’t do anything for this. Just make sure that your order has been set up correctly and Prebid MoPub adapter is added to the project.
BannerAdUnit
with MediationBannerAdUnit
.Integration example:
// 1. Create an MoPub's Interstitial Controller
interstitialController = MPInterstitialAdController.init(forAdUnitId: MOPUB_AD_UNIT_ID)
interstitialController.delegate = self
// 2. Create an In-App Bidding Interstitial Ad Unit
interstitialAdUnit = MediationInterstitialAdUnit(configID: CONFIG_ID,
minSizePercentage: CGSize(width: 30, height: 30),
mediationDelegte: MoPubMediationDelegate() )
// 3. Run an Header Bidding auction on Prebid
interstitialAdUnit.fetchDemand(with: interstitialController!) { [weak self] result in
// 4. Load an Ad
self?.interstitialController.loadAd()
}
// .....
// 5. Show the ad
if interstitialController.ready {
interstitialController.show(from: self)
}
The way of displaying Video Interstitial Ad is almost the same with two differences:
minSizePercentage
// 1. Create an MoPub's Interstitial Controller
interstitialController = MPInterstitialAdController.init(forAdUnitId: MOPUB_AD_UNIT_ID)
interstitialController.delegate = self
// 2. Create an In-App Bidding Interstitial Ad Unit
interstitialAdUnit = MediationInterstitialAdUnit(configID: CONFIG_ID,
minSizePercentage: CGSize(width: 30, height: 30),
mediationDelegate: MoPubMediationDelegate())
interstitialAdUnit.adFormat = .video
// 3. Run an Header Bidding auction on Prebid
interstitialAdUnit.fetchDemand(with: interstitialController!) { [weak self] result in
// 4. Load an Ad
self?.interstitialController.loadAd()
}
// .....
// 5. Show the ad
if interstitialController.ready {
interstitialController?.show(from: self)
}
Follow the MoPub Instructions and intgrate Interstital ad unit.
Create the MediationInterstitialAdUnit
object with parameters:
configID
- an ID of Stored Impression on the Prebid servermediationDelegate
- the object from the MoPubAdapters framework responsible for managing MoPub’s ad objects.Run the fetchDemand()
method which performs several actions:
When the bid request is completed, the responsibility of making the Ad Request is passed to the publisher. You have to invoke loadAd()
on the MoPub’s Ad View explicitly in the completion handler of the fetchDemand()
.
If the Prebid bid wins on MoPub it will be rendered by MoPubInterstitialAdapter
. You shouldn’t do anything for this. Just make sure that your order has been set up correctly and an adapter is added to the project
Pay attention that due to the expiration, the ad could become invalid with time. So it is always useful to check the availability with interstitialController?.isReady
before displaying it.
InterstitialAdUnit
with MediationInterstitialAdUnit
.Integration example:
// 1. Create an In-App Bidding Interstitial Ad Unit
rewardedAdUnit = MediationRewardedAdUnit(configID: CONFIG_ID)
// 2. Run an Header Bidding auction on Prebid
let bidInfoWrapper = MediationBidInfoWrapper()
rewardedAdUnit.fetchDemand(with: bidInfoWrapper) { [weak self] result in
guard let self = self else {
return
}
// 3. Load an Ad
MPRewardedVideo.setDelegate(self, forAdUnitId: self.MOPUB_AD_UNIT_ID)
MPRewardedVideo.loadAd(withAdUnitID: self.MOPUB_AD_UNIT_ID,
keywords: bidInfoWrapper.keywords as String?,
userDataKeywords: nil,
customerId: "testCustomerId",
mediationSettings: [],
localExtras: bidInfoWrapper.localExtras)
}
/// .......
// 4. Try to Display an Ad
if MPRewardedVideo.hasAdAvailable(forAdUnitID: MOPUB_AD_UNIT_ID) {
let rewards = MPRewardedVideo.availableRewards(forAdUnitID: MOPUB_AD_UNIT_ID)
guard let reward = rewards?.first as? MPRewardedVideoReward else {
return
}
// 5. Present Ad
MPRewardedVideo.presentAd(forAdUnitID: MOPUB_AD_UNIT_ID, from: self, with: reward, customData: nil)
}
Create the MediationRewardedAdUnit
object with parameter:
configID
- an ID of Stored Impression on the Prebid serverCall the fetchDemand()
method which does several things:
MediationBidInfoWrapper
When the bid request is completed, the responsibility of making the Ad Request is passed to the publisher. You have to invoke loadAd()
on the MoPub’s Ad View explicitly in the completion handler of the fetchDemand()
.
If the Prebid bid wins on MoPub it will be rendered by MoPubRewardedVideoAdapter
. You shouldn’t do anything for this. Just make sure that your order has been set up correctly and an adapter is added to the project
RewardedVideoAdUnit
with MediationRewardedAdUnit
.