> For the complete documentation index, see [llms.txt](https://aatkit.gitbook.io/rtbsdk-android-integration/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aatkit.gitbook.io/rtbsdk-android-integration/formats/banner.md).

# Banner

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`](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-view/index.html):

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

The [banner size](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-size/index.html) will be used later while loading a new banner ad.

### Listen to Callbacks

Through the use of [`RTBBannerViewDelegate`](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-view-delegate/index.html), you can listen to the different callbacks.

```kotlin
bannerAdView.delegate = this
```

### Request Ad

To load a banner ad, you will need to pass an instance of [RTBBannerRequestConfiguration](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-request-configuration/index.html) with `placementID` and the `bundleId`. Please contact our [support](mailto:support@gravite.net) for getting the needed IDs.

```kotlin
val rtbBannerRequestConfiguration = RTBBannerRequestConfiguration(<PLACEMENT_ID>, <BUNDLE_ID>)
rtbBannerRequestConfiguration.sellerId = "<SELLERID>" // Optional
rtbBannerRequestConfiguration.bidFloor = <BID_FLOOR>  // Optional
bannerAdView.load(rtbBannerRequestConfiguration)
```

You will be notified about the loading success/failure through the [`RTBBannerViewDelegate`](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-banner-view-delegate/index.html)

{% hint style="info" %}
The currency of `bidFloor` and `priceCPM` parameters is USD.
{% endhint %}

#### Optional - set user targeting <a href="#complete-code-example" id="complete-code-example"></a>

You can pass user targeting data to each request, allowing ads to be more relevant to your audience. Each field in [RTBUserTargeting](https://gravite-sdk-releases.s3.eu-central-1.amazonaws.com/rtbsdk/android/docs/-r-t-b--s-d-k/com.rtb.sdk/-r-t-b-user-targeting/index.html) is optional.

```kotlin
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 <a href="#complete-code-example" id="complete-code-example"></a>

```kotlin
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(<PLACEMENT_ID>, <BUNDLE_ID>)
        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
    }

}
```
