Adaptive sticky banner
That is a small, automatically updated ad placed at the top or bottom of the app screen. It does not overlap the main app content and is often used in game apps.
Adaptive sticky banners provide maximum efficiency by optimizing the size of the ad on each device. This ad type lets developers set a maximum allowable ad width, though the optimal ad size is still determined automatically. The height of the adaptive sticky banner shouldn't exceed 15% of the screen height.
Appearance
This guide shows how to integrate an adaptive sticky 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
- Follow the SDK integration steps described in Quick start.
- Initialize your ad SDK in advance.
- 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 sticky banner:
- Use the
Bannercomposable with theBannerSize.Stickysize. - Optionally pass
BannerEventsto track ad events.
Adaptive sticky banner integration notes
-
All Yandex Mobile Ads SDK method calls must be made from the main thread.
-
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. -
Adaptive sticky 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.
-
The ad size is set via
BannerSize.Sticky(width), where width is specified in dp. The Context for calculation is resolved automatically inside the composable. Height is calculated automatically. -
If you have mediation enabled, it is advisable to wait for initialization to complete before calculating sticky banner sizes. Prior to initialization, only a preliminary size is available, which may change after actual settings are received.
-
The sticky banner size remains constant for the same device. Once you have tested your app layout on a specific device, you can be confident the ad size will not change.
-
The adaptive sticky banner height will not exceed 15% of the screen height and will be at least 50dp.
-
The
Bannercomposable automatically loads and destroys the ad in accordance with the Compose lifecycle. Manual management ofBannerAdViewis not required. IfadRequestoradSizechange,BannerAdViewis recreated automatically.
Loading and displaying ads
To display a sticky banner, use the Banner composable with the BannerSize.Sticky size. Specify the width 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 sticky 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.Sticky(width = 320),
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.Sticky(width = 320),
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 sticky banner integration
Using demo ad units for ad testing
We recommend using test ads to test your adaptive sticky 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 check your adaptive sticky 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
-
Link to GitHub.