General changes
Renamed the MobileAds class to YandexAds.
Renamed the following properties and methods:
|
SDK 7
|
SDK 8
|
|
MobileAds.setLocationConsent(bool)
|
YandexAds.setLocationTracking(bool)
|
|
MobileAds.setAgeRestrictedUser(bool)
|
YandexAds.setAgeRestricted(bool)
|
Ad request
Removed the AdRequestConfiguration class. Use AdRequest instead, which now includes adUnitId.
Targeting fields (age, contextQuery, contextTags, gender, location) have been moved from AdRequest into a new AdTargeting class.
|
Ad request
|
SDK 7
final adRequestConfiguration = AdRequestConfiguration(
adUnitId: 'your-ad-unit-id',
age: 25,
contextQuery: 'query',
parameters: {'key': 'value'},
);
await adLoader.loadAd(
adRequestConfiguration: adRequestConfiguration,
);
SDK 8
final adRequest = AdRequest(
adUnitId: 'your-ad-unit-id',
targeting: AdTargeting(
age: 25,
contextQuery: 'query',
),
parameters: {'key': 'value'},
);
final ad = await adLoader.loadAd(adRequest: adRequest);
|
Fullscreen ads (interstitial, rewarded, app open)
We changed the approach to creating and loading fullscreen ads. The loader constructor is now synchronous and loadAd returns the loaded ad directly as a Future.
Removed the InterstitialAdLoadListener, RewardedAdLoadListener, and AppOpenAdLoadListener classes.
|
Ad loading
|
SDK 7
Asynchronous creation with callbacks:
late final Future<InterstitialAdLoader> _adLoader =
_createInterstitialAdLoader();
InterstitialAd? _ad;
Future<InterstitialAdLoader> _createInterstitialAdLoader() {
return InterstitialAdLoader.create(
onAdLoaded: (InterstitialAd interstitialAd) {
_ad = interstitialAd;
},
onAdFailedToLoad: (error) {
},
);
}
Future<void> _loadInterstitialAd() async {
final adLoader = await _adLoader;
await adLoader.loadAd(adRequestConfiguration: AdRequestConfiguration(adUnitId: 'your-ad-unit-id'));
}
SDK 8
Synchronous creation, loadAd returns the loaded ad or throws AdRequestError:
final _adLoader = InterstitialAdLoader();
InterstitialAd? _ad;
Future<void> _loadInterstitialAd() async {
try {
_ad = await _adLoader.loadAd(
adRequest: AdRequest(adUnitId: 'your-ad-unit-id'),
);
} on AdRequestError catch (error) {
}
}
|
The same changes apply to RewardedAdLoader and AppOpenAdLoader.
Banners
We changed the approach to creating and loading banner ads. The banner constructor no longer accepts adRequest or callbacks. Loading is now explicit via load(AdRequest). Ad state and events are delivered through streams.
|
Banner ad creation and loading
|
SDK 7
BannerAd? _banner;
void _createBanner() {
_banner = BannerAd(
adSize: BannerAdSize.stickySize(width),
adRequest: AdRequest(),
onAdLoaded: () {
},
onAdFailedToLoad: (error) {
},
onAdClicked: () {},
onImpression: (data) {},
);
}
SDK 8
BannerAd? _banner;
void _createBanner() {
final banner = BannerAd(adSize: BannerAdSize.stickySize(width));
banner.loadStateStream.listen((state) {
if (state is BannerAdLoadStateLoaded) {
} else if (state is BannerAdLoadStateError) {
}
});
banner.events.listen((event) {
if (event is BannerAdClickedEvent) {
} else if (event is BannerAdImpressionEvent) {
}
});
banner.load(AdRequest(adUnitId: 'your-ad-unit-id'));
_banner = banner;
}
|
|
Banner ad destroy
|
SDK 7
SDK 8
await _banner?.destroy();
|
Ad info
The AdInfo class has been restructured. Removed the adSize field. Added creatives, extraData, and partnerText fields.
|
SDK 7
|
SDK 8
|
|
AdInfo.adSize
|
Removed
|
|
—
|
AdInfo.creatives (List<Creative>)
|
|
—
|
AdInfo.extraData (String?)
|
|
—
|
AdInfo.partnerText (String?)
|
Removed events
Removed the onLeftApplication, onReturnedToApplication, and onAdClose callback events.