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.
Typically, this format is used in feed-based apps or contexts where it's acceptable to primarily focus user attention on ads.
Appearance
This guide covers the process of integrating adaptive inline banners into Compose Multiplatform apps. Besides code samples and instructions, it also 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 inline banners:
- Create state with
rememberBannerAdState()and theBannerAdSize.Inlinesize (width and maximum height indp). Optionally passBannerEvents. - Start loading by calling
loadAd(AdRequest)— typically fromLaunchedEffectonce the slot id and dimensions are ready. - Pass the state to the
Bannercomposable through thestateparameter.
Example placement on a screen:
@Composable
fun BannerSlot(adRequest: AdRequest, width: Dp, maxHeight: Dp) {
val bannerState = rememberBannerAdState(
adSize = BannerAdSize.Inline(width, maxHeight),
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 the container width from the available area: prefer the full width of the parent or screen, accounting for padding and safe areas.
After a successful load, the ad is shown automatically. When the user leaves the screen, remove Banner from composition; when the slot should appear again, call loadAd with a new AdRequest or recreate the state.
Specifics of adaptive inline 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. -
For adaptive inline banners to work correctly, make your app layouts adaptive. Otherwise ads may render incorrectly.
-
Adaptive inline banners work best at the full available width. In most cases that is the device screen width. Account for padding and the safe area.
-
Adaptive inline banners are intended for scrollable content. Height may be comparable to the screen height or capped by a maximum, depending on the API.
-
The
BannerAdSize.Inline(width, maxHeight)value carries parameters for server-side size selection; the rendered height may change between loads.
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.
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.