Banner

Integrate banner ads

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 RTBBannerView:

val bannerAdView = RTBBannerView(this)
bannerAdView.bannerSize = RTBBannerSize.banner320x50

The banner size will be used later while loading a new banner ad.

Listen to Callbacks

Through the use of RTBBannerViewDelegate, 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 RTBBannerRequestConfiguration with placementID and the bundleId. Please contact our support for getting the needed IDs.

val rtbBannerRequestConfiguration = RTBBannerRequestConfiguration(placementId, bundleId)
rtbBannerRequestConfiguration.sellerId = "<SELLERID>" // Optional
rtbBannerRequestConfiguration.bidFloor = <BID_FLOOR>  // Optional
bannerAdView.load(rtbBannerRequestConfiguration)

You will be notified about the loading success/failure through the RTBBannerViewDelegate

The currency of bidFloor and priceCPM parameters is USD.

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
    }

}

Last updated