Adaptive sticky banner

An adaptive sticky banner is a small, automatically updated ad placed at the bottom or top of the app screen. It doesn't overlap the main content and is often used in gaming apps.

The adaptive sticky banner delivers maximum performance by optimizing the ad size for each device. With this ad type, developers can set the maximum allowable ad width, and the system determines the optimal ad size automatically.

Appearance

This guide shows how to integrate adaptive sticky banners into Compose Multiplatform apps. In addition to code samples and instructions, it contains format-specific recommendations and links to additional resources.

Prerequisite

  1. Follow the process in Quick start to integrate the Yandex Mobile Ads Compose Multiplatform Plugin.
  2. Make sure you're running the latest Yandex Mobile Ads Compose Multiplatform Plugin version. If you're using mediation, make sure you're running the latest version of the unified build.

Implementation

Key steps for integrating adaptive sticky banners:

  1. Create state with rememberBannerAdState() and the BannerAdSize.Sticky size (container width in dp). Optionally pass BannerEvents.
  2. Start loading by calling loadAd(AdRequest) — typically from LaunchedEffect once the slot id and width are ready.
  3. Pass the state to the Banner composable through the state parameter.

Example placement on a screen:

@Composable
fun StickyBannerSlot(adRequest: AdRequest, width: Dp) {
    val bannerState = rememberBannerAdState(
        adSize = BannerAdSize.Sticky(width),
        events = BannerEvents(
            onAdLoaded = { adInfo -> /* ad loaded */ },
            onAdFailedToLoad = { error -> /* handle error */ },
            onAdClicked = { /* ad clicked */ },
            onImpression = { data -> /* impression tracked */ },
        ),
    )

    LaunchedEffect(adRequest) {
        bannerState.loadAd(adRequest)
    }

    Banner(
        state = bannerState,
        modifier = Modifier.fillMaxWidth(),
    )
}

You need an adUnitId from the Yandex Advertising Network interface. While integrating, you can use demo-banner-yandex; replace it with your production id before release. Extend the request through AdRequest (for example targeting, parameters, preferredTheme) — extra context improves ad selection. Read more in Ad Targeting.

Set width from the available area: prefer the full width of the parent or screen, accounting for padding and safe areas. Ad height is chosen automatically.

After a successful load, the ad is shown automatically. When the slot is no longer needed, remove Banner from composition; when it should appear again, call loadAd with a new AdRequest or recreate the state.

Specifics of adaptive sticky banner integration

  1. If onAdFailedToLoad reports an error, do not immediately try to load another ad. If you must retry, cap the number of attempts — this reduces the risk of repeated failed requests and connectivity issues when the network throttles you.

  2. Adaptive sticky banners work best at the full available width. In most cases that is the device screen width. Account for padding and the safe area.

  3. If mediation is enabled, wait until the SDK has finished initializing before you finalize layout for the sticky banner: until then you may only have a provisional size that changes once settings are applied.

  4. For a given device, sticky banner size stays stable: after you validate layout on a device, you can rely on the same size class.

  5. Adaptive sticky banner height is at least 50 dp and at most 15% of the screen height.

Testing adaptive sticky banner integration

Using demo ad units for ad testing

Use test ads to check your adaptive sticky 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 sticky 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.

Using demo ad units for ad testing

We recommend using test ads to test your ad 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 to the store, make sure you replace the demo ad unit 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 ad integration using the native Console tool.

To view detailed logs, call the YandexAds class's enableLogging method.

YandexAds.enableLogging()

To view SDK logs, go to the Console tool and set Subsystem = com.mobile.ads.ads.sdk. You can also filter logs by category and error level.

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

Additional resources