RTBSDK Android Integration
Release Notes
  • Start
    • Setup
      • Maven
      • Configure RTBSDK
    • Consent
  • Formats
    • Banner
    • Fullscreen (Interstitial)
    • Native Ads
    • Advanced
      • Separate Loading and Rendering of Banner Ads
  • Other
    • AppLovin Custom Adapter
    • AdMob Custom Events
    • Reference
      • Classes
        • RTBSDKManager
        • RTBBannerView
        • RTBBannerAdProvider
        • RTBBannerRequestConfiguration
        • RTBBannerSize
        • RTBFullscreenAd
        • RTBFullscreenRequestConfiguration
        • RTBBidInfo
        • RTBNativeAd
        • RTBNativeAdRequestConfiguration
        • RTBUserTargeting
        • RTBNativeAdLoader
      • Interfaces
        • RTBBannerViewDelegate
        • RTBBannerAdLoadDelegate
        • RTBBannerAdInteractionDelegate
        • RTBFullscreenDelegate
        • RTBNativeAdLoadDelegate
        • RTBNativeAdInteractionDelegate
      • Enumerations
        • RTBGender
  • Sample App
Powered by GitBook
On this page
  • Create an RTBBannerView Instance
  • Listen to Callbacks
  • Request Ad
  • Complete Code Example
  1. Formats

Banner

Integrate banner ads

PreviousFormatsNextFullscreen (Interstitial)

Last updated 2 months ago

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.

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

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.

RTBBannerView
banner size
RTBBannerViewDelegate
RTBBannerRequestConfiguration
support
RTBBannerViewDelegate
RTBUserTargeting