Back to Bidding-Only Integration
Integration example:
private fun createAd() {
// 1. Create RewardedVideoAdUnit
adUnit = RewardedVideoAdUnit(CONFIG_ID)
// 2. Configure Video parameters
adUnit?.videoParameters = configureVideoParameters()
// 3. Build the Next-Gen SDK ad request
val request = AdRequest.Builder(AD_UNIT_ID)
adUnit?.fetchDemand(request) {
// 4. Load a Next-Gen Rewarded Ad
RewardedAd.load(
request.build(),
createListener()
)
}
}
Configure video ad unit:
private fun configureVideoParameters(): VideoParameters {
return VideoParameters(listOf("video/mp4")).apply {
protocols = listOf(Signals.Protocols.VAST_2_0)
playbackMethod = listOf(Signals.PlaybackMethod.AutoPlaySoundOff)
}
}
Implement Rewarded ad listener:
private fun createListener(): AdLoadCallback<RewardedAd> {
return object : AdLoadCallback<RewardedAd>() {
override fun onAdLoaded(rewardedAd: RewardedAd) {
super.onAdLoaded(rewardedAd)
// 5. Display rewarded ad
rewardedAd.show(
this@Activity
) { _ -> }
}
override fun onAdFailedToLoad(adError: LoadAdError) {
super.onAdFailedToLoad(adError)
Log.e(TAG, "Ad failed to load: $adError")
}
}
}
Initialize the Rewarded Video Ad Unit with the following properties:
configId - an ID of Stored Impression on the Prebid ServerProvide configuration properties for the video ad using the VideoParameters object.
The fetchDemand method makes a bid request to the Prebid Server. You should provide an AdRequest.Builder object to this method so Prebid SDK sets the targeting keywords of the winning bid for future ad requests.
Now you should request the ad from the Next-Gen SDK. If the AdRequest contains targeting keywords, the respective Prebid line item will be returned from GAM, and the Next-Gen SDK will render its creative.
Be sure that you make the ad request with the same AdRequest.Builder object that you passed to the fetchDemand method. Otherwise, the ad request won’t contain targeting keywords, and Prebid’s ad won’t ever be displayed.
Follow the Next-Gen SDK guide to display a rewarded ad right after receiving it or later in natural pauses in the flow of an app.