Back to Bidding-Only Integration
Starting with Prebid Mobile 2.1.0
you can use BannerAdUnit
to bid over the banner and/or video demand. The default ad format is BANNER
. To customize the bidding format, specify the ad formats in the BannerAdUnit
constructor.
Integration example:
private fun createAd() {
// 1. Create BannerAdUnit
adUnit = BannerAdUnit(CONFIG_ID, WIDTH, HEIGHT)
adUnit?.setAutoRefreshInterval(refreshTimeSeconds)
// 2. Configure banner parameters
val parameters = BannerBaseAdUnit.Parameters()
parameters.api = listOf(Signals.Api.MRAID_3, Signals.Api.OMID_1)
adUnit?.parameters = parameters
// For multi-size request
adUnit?.addAdditionalSize(728, 90)
// 3. Create AdManagerAdView
val adView = AdManagerAdView(this)
adView.adUnitId = AD_UNIT_ID
adView.setAdSizes(AdSize(WIDTH, HEIGHT))
adView.adListener = createGAMListener(adView)
// Add GMA SDK banner view to the app UI
adWrapperView.addView(adView)
// 4. Make a bid request to Prebid Server
val request = AdManagerAdRequest.Builder().build()
adUnit?.fetchDemand(request) {
// 5. Load GAM Ad
adView.loadAd(request)
}
}
It may be necessary to implement AdListener to adjust banner view size according to the creative size, for the case where there are several ad sizes supported. This logic is not needed for a single size banner:
Prebid SDK can be thought of an OpenRTB request synthesizer. OpenRTB does not have a notion of adaptive banners, but it has a notion of several banner sizes / formats in one request. So an adaptive banner may be represented as a request containing several banner sizes, e.g. a fixed width that equals the size of the screen and several different heights. The examples here deal with a single ad size, but more can be added via BannerParameters.adSizes array.
GAM ad view listener:
private fun createGAMListener(adView: AdManagerAdView): AdListener {
return object : AdListener() {
override fun onAdLoaded() {
super.onAdLoaded()
// 6. Resize ad view if needed
AdViewUtils.findPrebidCreativeSize(adView, object : AdViewUtils.PbFindSizeListener {
override fun success(width: Int, height: Int) {
adView.setAdSizes(AdSize(width, height))
}
override fun failure(error: PbFindSizeError) {}
})
}
}
}
Notes:
Initialize the BannerAdUnit
with properties:
configId
- an ID of the Stored Impression on the Prebid Serverwidth
- the width of the ad unit which will be used in the bid request.height
- the height of the ad unit which will be used in the bid request.Using the BannerParameters
object you can customize the bid request for banner ads.
Starting from PrebidMobile 2.1.0
the BannerBaseAdUnit.Parameters
class is deprecated. Use BannerParameters
instead.
Defines the OpenRTB banner.formats array.
For interstitials only, these define which sizes Prebid Server will choose to send to bidders. See Prebid Server interstitial support. If this option is used, you’ll need to set the size to 1x1.
The api
property is dedicated to adding values for API Frameworks to bid response according to the OpenRTB 2.6 spec. The supported values for GMA SDK integration are:
3
or Signals.Api.MRAID_1
: MRAID-1 support signal5
or Signals.Api.MRAID_2
: MRAID-2 support signal6
or Signals.Api.MRAID_3
: MRAID-3 support signal7
or Signals.Api.OMID_1
: signals OMSDK supportFollow the GMA SDK documentation to integrate a banner ad unit.
The fetchDemand
method makes a bid request to the Demand Manager. You should provide an AdManagerAdRequest
object to this method. Prebid SDK will set the targeting keywords of the winning bid into provided object. Eventually you should use this object to make an ad request to GAM.
You should now request the ad from GAM. If the AdManagerAdRequest
contains targeting keywords, the respective Prebid line item will be returned from GAM, and GMA SDK will render its creative.
Be sure that you make the ad request with the same AdManagerAdRequest
object that you passed to the fetchDemand
method. Otherwise, the ad request won’t contain the targeting keywords, and Prebid’s ad won’t ever be displayed.
Once an app receives a signal that an ad is loaded, you should use the method AdViewUtils.findPrebidCreativeSize
to verify whether it’s Prebid’s ad and resize the ad slot respectively to the creative’s properties.
Notes: