Adaptive inline banner

An adaptive inline banner is a flexible banner ad format that ensures maximum efficiency by optimizing ad size for each device.

With this ad type, developers can set the maximum allowable ad width and height, and the system determines the optimal ad size automatically. To choose the best ad size, adaptive inline banners use a maximum height instead of a fixed one. This helps improve performance.

Typically, this format is used in feed-based apps or contexts where it's acceptable to focus user attention on ads.

Appearance

This guide covers the process of integrating adaptive inline banners into Android apps using the Jetpack Compose extension. Besides code samples and instructions, it contains recommendations and links to additional resources.

Prerequisite

  1. Follow the SDK integration steps described under Quick start.
  2. First, you need to initialize the advertising SDK.
  3. Make sure you have the latest Yandex Mobile Ads SDK version. If you're using mediation, update to the most recent single build version.

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

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

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

Implementation

Key steps for integrating adaptive inline banners:

  1. Use a Banner composable with the BannerSize.Inline size.
  2. If needed, pass BannerEvents to track ad events.

Specifics of adaptive inline banner integration

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

  2. To make sure video ads display correctly on the app screen, enable hardware acceleration. Hardware acceleration is enabled by default, but some apps may choose to disable it. If your app disables hardware acceleration, we recommend enabling it for Activity classes that use ads.

  3. If the onAdFailedToLoad() callback returns an error, don't try to load a new ad again. If you have to, limit the number of ad loading retries to avoid unsuccessful requests and connection issues.

  4. For adaptive inline banners to work properly, make your app layouts adaptive. Otherwise, your ads might render incorrectly.

  5. Adaptive inline banners work best when utilizing the full available width. In most cases, this will be the full width of the device screen. Consider the padding parameters set in your app and the display's safe area.

  6. Adaptive inline banners are designed to be placed in scrollable content. Their height can be the same as the device screen or limited by the maximum height, depending on the API.

  7. The ad size is defined using BannerSize.Inline(width, maxHeight), with both the width and maximum height specified in dp. The context for this calculation is resolved automatically within the composable.

  8. The Banner composable automatically handles ad loading and disposal according to the Compose lifecycle. You don't need to manage the BannerAdView manually. If the adRequest or adSize changes, the 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 rendering ads

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

The composable automatically handles size calculations, ad loading, and impressions. You don't need to manually manage the BannerAdView lifecycle.

To load ads, you need the ad placement ID obtained in the Yandex Advertising Network interface.

You can expand the ad request parameters using AdRequest.Builder(). To do this, pass information about the user's interests, page context, location, and other additional data in the request. Context can greatly improve the ad quality. To learn more, see Ad targeting.

Sample adaptive inline banner

Once loaded, 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 click") },
            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

Use test ads to check your adaptive inline banner integration and the app itself. To make sure that test ads are returned for each ad request, you can use a special demo ad placement ID.

Demo adUnitId: demo-banner-yandex.

Warning

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

For the list of all available demo ad placement IDs, see Demo ad units for testing.

Testing ad integration

You can check if your adaptive inline banners are integrated correctly using the SDK's built-in analyzer. A detailed report with the test results will appear in the log.

To view the report, search for the keyword “YandexAds” in Logcat, a tool for debugging Android apps.

adb logcat -v brief '*:S YandexAds'

If the integration is successful, the following message is returned:

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

If there are any banner integration issues, you'll get a detailed issue report and troubleshooting recommendations.

Additional resources