Banner ads are displayed in RTBBannerView instances, so the first step towards integrating banner ads is to create an instance of RTBBannerView and add it to your view hierarchy.
Create an RTBBannerView Instance
Create an instance of :
val bannerAdView = RTBBannerView(this)
bannerAdView.bannerSize = RTBBannerSize.banner320x50
The will be used later while loading a new banner ad.
Listen to Callbacks
Through the use of , you can listen to the different callbacks.
bannerAdView.delegate = this
Request Ad
To load a banner ad, you will need to pass an instance of with placementID and the bundleId. Please contact our for getting the needed IDs.
You will be notified about the loading success/failure through the
The currency of bidFloor and priceCPM parameters is USD.
Optional - set user targeting
rtbBannerRequestConfiguration.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
Complete Code Example
class MainActivity : AppCompatActivity(), RTBBannerViewDelegate {
private var bannerAdView: RTBBannerView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
bannerAdView = RTBBannerView(this)
bannerAdView?.bannerSize = RTBBannerSize.banner320x50
// Set the banner delegate to listen to events
bannerAdView?.delegate = this
// [Important] Add bannerView to your view hierarchy based on your screen layout
// Request a banner ad using the placement ID and bundle ID
val rtbBannerRequestConfiguration = RTBBannerRequestConfiguration(placementId, bundleId)
rtbBannerRequestConfiguration.sellerId = "<SELLERID>" // Optional
bannerAdView?.load(rtbBannerRequestConfiguration)
}
// RTBBannerViewDelegate implementation:
override fun bannerViewDidReceiveAd(bannerView: RTBBannerView, bidInfo: RTBBidInfo, networkName: String)
// A banner ad has been loaded
}
override fun bannerViewDidFailToReceiveAd(bannerView: RTBBannerView, error: String, networkName: String) {
// Failed to load a banner ad
}
override fun bannerViewDidRecordClick(bannerView: RTBBannerView, networkName: String) {
// The banner received a click
}
override fun bannerViewDidPauseForAd(bannerView: RTBBannerView, networkName: String) {
// The app paused after the user clicked on the ad and opened web browser app
}
override fun bannerViewDidResumeAfterAd(bannerView: RTBBannerView, networkName: String) {
// The app resumed after returning from web browser as a result of user click
}
}
You can pass user targeting data to each request, allowing ads to be more relevant to your audience. Each field in is optional.