Adaptive inline banner

Adaptive inline banners are a flexible format of banner advertising, providing maximum efficiency by optimizing the size of the ad on each device.

This ad type lets developers set a maximum allowable width and height for the ad, though the optimal ad size is still determined automatically. To select the best ad size, built-in adaptive banners use the maximum height rather than the fixed height. That provides room for improving performance.

This format is typically used in feed-based apps or where keeping the primary focus on the ad is acceptable.

Appearance

This guide shows how to integrate an adaptive inline banner into an Android app using the Jetpack Compose extension. In addition to code examples and instructions, it provides recommendations on using this ad format and links to additional resources.

Prerequisite

  1. Follow the SDK integration steps described in Quick start.
  2. Initialize your ad SDK in advance.
  3. Make sure you're running the latest Yandex Mobile Ads SDK version. If you're using mediation, make sure you're also running the latest version of the unified build.

To use the Compose extension, add the dependency to build.gradle.kts:

dependencies {
    implementation("com.yandex.android:mobileads:8.0.0")
    implementation("com.yandex.android:mobileads-compose:8.0.0")

    // Compose BOM (minimum 2024.01.00)
    implementation(platform("androidx.compose:compose-bom:2025.03.00"))
}

Implementation

Key steps for integrating an adaptive inline banner:

  • Use the Banner composable with the BannerSize.Inline size.
  • Optionally pass BannerEvents to track ad events.

Adaptive inline banner integration notes

  1. All Yandex Mobile Ads SDK method calls must be made from the main thread.

  2. For video ads to render correctly in your app, enable hardware acceleration. Hardware acceleration is enabled by default, but some apps disable it. If your app does, it is recommended to enable hardware acceleration for activities that display ads.

  3. If you receive an error in the onAdFailedToLoad() callback, do not attempt to load a new ad immediately. If you must retry, limit the number of reload attempts to avoid continuous failed requests and connection issues under restricted conditions.

  4. For adaptive inline banners to work correctly, make your app layouts adaptive. Failing to do so may result in incorrect ad rendering.

  5. Adaptive inline banners work best when using the full available width. In most cases, this will be the full screen width of the device. Make sure to account for any app padding and display safe areas.

  6. The adaptive inline banner is designed for placement in scrollable content. The banner height can match the device screen height or be limited to a maximum height, depending on the API.

  7. The ad size is set via BannerSize.Inline(width, maxHeight), where width and max height are specified in dp. The Context for calculation is resolved automatically inside the composable.

  8. The Banner composable automatically loads and destroys the ad in accordance with the Compose lifecycle. Manual management of BannerAdView is not required. If adRequest or adSize change, BannerAdView is recreated automatically.

  1. The height of the top non-clickable safe zone is 80 dp. Controls within the zone can be clickable.

  2. Visual elements (assets) must be at least 32×32 dp in size. These include the Close button as well as all other icons.

  3. Clickable area around assets must be at least 64×64 dp. For example, if an asset measures 32×32 dp, the padding around it must ensure that the total clickable area is 64×64 dp.

  4. If a control appears with a delay, you must display a timer or progress bar until the element loads.

Example

Loading and displaying ads

To display an inline banner, use the Banner composable with the BannerSize.Inline size. Specify width and maximum height in dp.

The composable automatically calculates the size, loads, and displays the ad. Manual lifecycle management of BannerAdView is not required.

To load an ad, you will need the ad unit ID obtained from the Yandex Advertising Network interface.

You can extend the ad request parameters via AdRequest.Builder() by passing user interest data, page context data, location, or other additional data. Additional contextual data in the request can significantly improve ad quality. For more information, see Ad targeting.

The following example shows how to display an adaptive inline banner. After a successful load, the banner is displayed automatically:

import com.yandex.mobile.ads.common.AdRequest
import com.yandex.mobile.ads.compose.Banner
import com.yandex.mobile.ads.compose.BannerSize

@Composable
fun MyScreen() {
    Banner(
        adRequest = AdRequest.Builder("your-ad-unit-id").build(),
        adSize = BannerSize.Inline(width = 320, maxHeight = 400),
        modifier = Modifier.fillMaxWidth(),
    )
}

To track ad events, pass BannerEvents:

import com.yandex.mobile.ads.common.AdRequest
import com.yandex.mobile.ads.compose.Banner
import com.yandex.mobile.ads.compose.BannerEvents
import com.yandex.mobile.ads.compose.BannerSize

@Composable
fun MyScreen() {
    Banner(
        adRequest = AdRequest.Builder("your-ad-unit-id").build(),
        adSize = BannerSize.Inline(width = 320, maxHeight = 400),
        modifier = Modifier.fillMaxWidth(),
        events = BannerEvents(
            onAdLoaded = { Log.d("YandexAds", "Banner loaded") },
            onAdFailedToLoad = { error -> Log.e("YandexAds", error.description) },
            onAdClicked = { Log.d("YandexAds", "Banner clicked") },
            onImpression = { data -> Log.d("YandexAds", "Impression: ${data?.rawData}") },
        )
    )
}

If you serve ads through Adfox, then after the banner ad response, the campaignId, bannerId, and placeId data can be accessed from the BannerAdView objects using the adAttributes property of the AdAttributes type.

Testing adaptive inline banner integration

Using demo ad units for ad testing

We recommend using test ads to test your adaptive inline banner integration and your app itself.

To guarantee that test ads are returned for every ad request, we created a special demo ad placement ID. Use it to check your ad integration.

Demo adUnitId: demo-banner-yandex.

Warning

Before publishing your app in the store, make sure to replace the demo ad placement ID with a real one obtained from the Yandex Advertising Network interface.

You can find the list of available demo ad placement IDs in the Demo ad units for testing section.

Testing ad integration

You can test your adaptive inline banner integration using the SDK's built-in analyzer.

The tool makes sure your ads are integrated properly and outputs a detailed report to the log. To view the report, search for the “YandexAds” keyword in the Logcat tool for Android app debugging.

adb logcat -v brief '*:S YandexAds'

If the integration is successful, you'll see this message:

adb logcat -v brief '*:S YandexAds'
mobileads$ adb logcat -v brief '*:S YandexAds'
I/YandexAds(13719): [Integration] Ad type banner was integrated successfully

If you're having problems integrating banner ads, you'll get a detailed report on the issues and recommendations for how to fix them.

Additional resources