(Beta) Hybrid Native Ads
This feature is currently in beta and only supported from version 1.9.0.
The RTBHybridNativeAdLoader allows to create an ad request that can return either native ad or banner. It can be treated as a combination of Native Ads and Manually Rendered Banner. See the guide below showing how to integrate hybrid native ads into your app.
Create RTBHybridNativeAdLoader
To make a hybrid request, first create and instance of RTBHybridNativeAdLoader, passing context instance and implementation of RTBHybridNativeAdLoadDelegate.
val loader = RTBHybridNativeAdLoader(context, loadListener)
Request Ad
To load an ad, you will need to pass an instance of RTBHybridNativeAdRequestConfiguration with placementId
and bundleId
. Please contact our support to get the needed IDs.
val request = RTBHybridNativeAdRequestConfiguration(placementId, bundleId)
request.sellerId = "<SELLERID>" // Optional
loader.load(request)
Optional - set user targeting
You can pass user targeting data to each request, allowing ads to be more relevant to your audience. Each field in RTBUserTargeting is optional.
request.userTargeting = RTBUserTargeting(userID = "<USER_ID>", gender = RTBGender.MALE, keywords = listOf("keyword1", "keyword2"), yearOfBirth = 1990)
// yearOfBirth must be a 4-digit number, otherwise it will be ignored
Handle ad response
As the request can return either banner or native ad, different flows need to be implemented for rendering the ad depending on the callback.
private fun createLoadListener(): RTBHybridNativeAdLoadDelegate {
return object : RTBHybridNativeAdLoadDelegate {
override fun hybridNativeAdDidReceiveNativeAd(nativeAd: RTBNativeAd, bidInfo: RTBBidInfo, networkName: String) {
// render as native ad
}
override fun hybridNativeAdDidReceiveBannerAd(bannerBid: RTBBannerBid, networkName: String) {
// render as banner
}
override fun hybridNativeAdDidFailToReceiveAd(errorMessage: String, networkName: String) {
//handle failure
}
}
}
Handling native ad response
If native ad is received, you can get the needed native ad assets to assemble your view. From now, the flow is just like with rendering classic native ads.
Handling banner response
If banner response is received, you can use the received RTBBannerBid
to obtain banner view from RTBBannerAdProvider
, just like with "Separate Loading and Rendering of Banner Ads" type of integration.
Last updated