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 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
- Follow the process in Quick start to integrate the Yandex Mobile Ads Compose Multiplatform Plugin.
- 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:
- Create state with
rememberBannerAdState()and theBannerAdSize.Stickysize (container width indp). Optionally passBannerEvents. - Start loading by calling
loadAd(AdRequest)— typically fromLaunchedEffectonce the slot id and width are ready. - Pass the state to the
Bannercomposable through thestateparameter.
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
-
If
onAdFailedToLoadreports 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. -
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.
-
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.
-
For a given device, sticky banner size stays stable: after you validate layout on a device, you can rely on the same size class.
-
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
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.
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
-
Link to GitHub.