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
  • Request Ad
  • Get Loaded Banner View
  • Complete Code Example
  1. Formats
  2. Advanced

Separate Loading and Rendering of Banner Ads

PreviousAdvancedNextOther

Last updated 2 months ago

The gives the app complete control over the lifecycle of a specific banner impression. Specifically, the app can load a banner ad separately from rendering it later. The app can load an ad with a specific configuration and get notified about the outcome of that specific load request via the . Hence, the usage of the differs from using .

Request Ad

To load a banner ad, you will need to pass an instance of with placementID and the bundleId. Please contact our to get the needed IDs.

val configuration = RTBBannerRequestConfiguration(placementId, bundleId)
configuration.sellerId = "<SELLERID>" // Optional
configuration.bidFloor = <BID_FLOOR>  // Optional
RTBBannerAdProvider.loadBannerAd(context, RTBBannerSize.banner320x50, rtbBannerRequestConfiguration, bannerLoadListener)

You will be notified about the loading success or failure through the instance passed as bannerLoadListener. If the ad loads successfully, you will obtain RTBBannerBid instance that can later be used to obtain banner view.

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 is optional.

configuration.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

Get Loaded Banner View

Once the banner is loaded and the method bannerAdDidReceiveAd() is called, you can get the loaded banner view by calling the RTBBannerAdProvider.getBannerView(context: Context, bannerBid: RTBBannerBid, listener: RTBBannerAdInteractionDelegate?): View method. You can also pass optional that will be notified about banner events like clicks.

override fun bannerAdDidReceiveAd(bannerBid: RTBBannerBid) {
    // Optionally - examine bid details:
    val priceCPM = bannerBid.priceCPM
    
    val bannerView = RTBBannerAdProvider.getBannerView(context, bannerBid, interactionListner)
    // Add the banner view to the layout
}

The currency of bidFloor and priceCPM parameters is USD.

Complete Code Example

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Prepare request configurations
        val configuration = RTBBannerRequestConfiguration(placementId, bundleId)
        configuration.sellerId = "<SELLERID>" // Optional
        configuration.bidFloor = <BID_FLOOR>  // Optional

        // Request a banner ad
        RTBBannerAdProvider.loadBannerAd(this, RTBBannerSize.banner320x50, rtbBannerRequestConfiguration, createBannerLoadDelegate())
    }
    
    private fun createBannerLoadDelegate(): RTBBannerAdLoadDelegate {
        return object : RTBBannerAdLoadDelegate {
            override fun bannerAdDidReceiveAd(bannerBid: RTBBannerBid) {
                // Banner has been loaded
                val banner = RTBBannerAdProvider.getBannerView(this, bannerBid, createInteractionDelegate())
                // Add the banner view to layout
            }

            override fun bannerAdDidFailToReceiveAd(errorMessage: String) {
                // Failed to load a banner ad
            }
        }
    }
    
    private fun createInteractionDelegate(): RTBBannerAdInteractionDelegate {
        return object : RTBBannerAdInteractionDelegate {
            override fun bannerAdDidRecordClick() {
                // The banner received a click
            }

            override fun bannerAdDidPauseForAd() {
                // The app paused after the user clicked on the ad
            }

            override fun bannerAdDidResumeAfterAd() {
                // The app resumed after returning from ad
            }

            override fun bannerAdDidFailToRender(error: String) {
                // Banner failed to render properly
            }
        }
    }

    
}

RTBBannerAdProvider
RTBBannerAdLoadDelegate
RTBBannerAdProvider
RTBBannerView
RTBBannerRequestConfiguration
support
RTBBannerAdLoadDelegate
RTBUserTargeting
interactionListener