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.
This guide covers the process of integrating adaptive inline banners into React Native apps. Besides code samples and instructions, it also contains format-specific recommendations and links to additional resources.
Prerequisite
- Follow the Yandex Mobile Ads React Native plugin integration steps described under Quick start.
- Make sure that you have the latest version of the Yandex Mobile Ads React Native plugin. If you're using mediation, update to the most recent single build version.
Implementation
Key steps for integrating adaptive inline banners:
- Get the banner size.
- Set up the parameters for loading ads using an
AdRequest
object. - Display the ad by setting the required properties and callback functions to handle events within the ad lifecycle.
Specifics of adaptive inline banner integration
-
We strongly discourage attempting to load a new ad when receiving an error in the
onAdFailedToLoad
callback. If you need to load an ad fromonAdFailedToLoad
, limit retry attempts to avoid recurring failed ad requests in case of network connection constraints. -
For adaptive inline banners to work properly, make your app layouts adaptive. Otherwise, your ads might render incorrectly.
-
Adaptive inline banners work best when utilizing the full available width. In most cases, this will be the full width of the device screen. Be sure to consider the padding parameters set in your app and the display's safe area.
-
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.
-
To get the size of the ad, use the method
BannerAdSize.inlineSize(width, maxHeight)
which accepts the available width of the ad container and the maximum acceptable ad height as arguments. -
The ad width and height values contained within a
BannerAdSize
object that was calculated using theBannerAdSize.inlineSize(width, maxHeight)
method are consistent across the same device. When testing your app's layout on a specific device, you can be sure that the ad size for that device will remain the same.
Getting the banner size
To get the size of the ad, use the method BannerAdSize.inlineSize(width, maxHeight)
which accepts the available width of the ad container and the maximum acceptable ad height as arguments. Be sure to consider the padding parameters set in your app and the display's safe area:
let adSize = await BannerAdSize.inlineSize(Dimensions.get('window').width, bannerMaxHeight);
Creating an AdRequest
You can expand the ad request parameters via the AdRequest
class object. You can provide information about the user's interests, page context, location, and other additional data. Extra context added to ad requests can greatly improve the ad quality.
Ad display
To load an ad, you need the size calculated using the BannerAdSize.inlineSize(width, maxHeight)
method as well as the placement ID that you obtained in the Partner Interface (adUnitId).
To enable notifications when ads load or fail to load and track an adaptive inline banner's lifecycle events, set callback functions for the BannerView
component.
You can also expand the request parameters by passing the adRequest
property of the BannerView
component to the AdRequest
class object.
The example below shows how to set the adaptive inline banner properties and the callback functions for handling its lifecycle events. Once loaded, the banner is displayed automatically:
const createBanner = async () => {
let adSize = await BannerAdSize.inlineSize(Dimensions.get('window').width, bannerMaxHeight);
let adRequest = new AdRequest({
age: '20',
contextQuery: 'context-query',
contextTags: ['context-tag'],
gender: Gender.Male,
location: new Location(55.734202, 37.588063)
});
return (
<BannerView
size={adSize}
adUnitId={'R-M-XXXXXX-Y'} // or 'demo-banner-yandex'
adRequest={adRequest}
onAdLoaded={() => console.log('Did load')}
onAdFailedToLoad={(event: any) => console.log(`Did fail to load with error: ${JSON.stringify(event.nativeEvent)}`)}
onAdClicked={() => console.log('Did click')}
onLeftApplication={() => console.log('Did leave application')}
onReturnToApplication={() => console.log('Did return to application')}
onAdImpression={(event: any) => console.log(`Did track impression: ${JSON.stringify(event.nativeEvent.impressionData)}`)}
onAdClose={() => console.log('Did close')}
/>
);
}
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 Partner 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 Partner 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 YMAMobileAds
class's enableLogging
method.
YMAMobileAds.enableLogging()
To view SDK logs, go to the Console tool and set sybsystem = com.yandex.mobile.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.