Guide to migrating to version 6

Other platforms

Warning

Be sure to update to the latest adapter versions (Yandex Mediation and adapters for third-party mediation networks). Otherwise, errors from improper adapter integration might occur, preventing the ad from being served.

For proper operation, enable custom templates for the generated project. To do this, in the build settings (Build Settings → Player Settings → Publishing Settings → Build), select Custom Main Gradle Template.

We recommend that you always enable Custom Main Gradle Template and Custom Gradle Properties Template when building a Unity app to avoid other potential errors.

Banners

Renamed the AdSize class to BannerAdSize. Removed the flexibleSize(int width, int maxHeight) method.

Use methods depending on your ad type:

To create an adaptive sticky banner, use the BannerAdSize.stickySize(int width) method.

An adaptive sticky banner is a small, automatically updated ad placed at the bottom or top of the app screen.

The banner doesn't overlap the main app content and is often used in gaming apps.

The height of the sticky banner is determined automatically, adapting to the device screen size and not exceeding 15% of the screen height.

Warning

Starting with version 6.0.0, adaptive sticky banners can refresh automatically.

If you previously implemented auto-refresh for a sticky-banner, you should now disable it.

To create an adaptive inline banner, use the BannerAdSize.inlineSize(int width, int maxHeight) method.

An adaptive inline banner is a flexible banner ad format that ensures maximum efficiency by optimizing ad size for each device.

The banner height is selected automatically and can reach the height of the device screen.

Typically, this format is used in feed-based apps or contexts where it's acceptable to primarily focus user attention on ads.

The fixedSize(int width, int height) method has been retained for backward compatibility, but we don't recommend using it. Use inlineSize(int width, int maxHeight) or stickySize(int width) instead. In SDK 6.1.0, banner height is calculated automatically and known before sending the ad request. This height can be used for screen layout design.

Rewarded ads

The approach to creating and loading advertisements has been revised. Now there's a RewardedAdLoader object responsible for loading ads and a RewardedAd object derived from the OnAdLoaded ad loading event.

To learn more about the new API, see the SDK reference.

Loading ads

SDK 5

One object is now used both for loading and serving ads:

private RewardedAd rewardedAd;

private void RequestRewardedAd()
{
    string adUnitId = "demo-rewarded-yandex"; // replace with "R-M-XXXXXX-Y"
    rewardedAd = new RewardedAd(adUnitId);

    AdRequest request = new AdRequest.Builder().Build();
    rewardedAd.LoadAd(request);
}

SDK 6

RewardedAdLoader is used for loading multiple ads.

private void SetupLoader()
{
  rewardedAdLoader = new RewardedAdLoader();
  rewardedAdLoader.OnAdLoaded += HandleRewardedAdLoaded;
  rewardedAdLoader.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
}

private void RequestRewardedAd()
{
    string adUnitId = "demo-rewarded-yandex"; // replace with "R-M-XXXXXX-Y"
    AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(adUnitId).Build();
    rewardedAdLoader.LoadAd(adRequestConfiguration);
}

public void HandleAdLoaded(object sender, RewardedAdLoadedEventArgs args)
{
    this.interstitial = args.RewardedAd;
}

public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    Debug.Log($"HandleAdFailedToLoad event received with message: {args.Message}");
}

Ad serving

SDK 5

Check if the ad is loaded before displaying it.

private void ShowRewardedAd()
{
    if (rewardedAd != null && rewardedAd.IsLoaded())
    {
        rewardedAd.Show();
    }
}

SDK 6

You don't need to check whether the ad has been loaded.

private void ShowRewardedAd()
{
    if (rewardedAd != null)
    {
        rewardedAd.Show();
    }
}

Subscribing to ad lifecycle events

SDK 5

All events come in a single RewardedAd object.

rewardedAd.OnRewardedAdLoaded += HandleRewardedAdLoaded;
rewardedAd.OnRewardedAdFailedToLoad += HandleRewardedAdFailedToLoad;
rewardedAd.OnReturnedToApplication += HandleReturnedToApplication;
rewardedAd.OnLeftApplication += HandleLeftApplication;
rewardedAd.OnAdClicked += HandleAdClicked;
rewardedAd.OnRewardedAdShown += HandleRewardedAdShown;
rewardedAd.OnRewardedAdFailedToShow += HandleRewardedAdFailedToShow;
rewardedAd.OnRewardedAdDismissed += HandleRewardedAdDismissed;
rewardedAd.OnImpression += HandleImpression;
rewardedAd.OnRewarded += HandleRewarded;

SDK 6

Ad loading events are received in the RewardedAdLoader object, and impression events in the RewardedAd object. Unified event names. Deleted the OnLeftApplication and OnReturnedToApplication events.

rewardedAdLoader.OnAdLoaded += HandleRewardedAdLoaded;
rewardedAdLoader.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
// ...
rewardedAd.OnAdClicked += HandleAdClicked;
rewardedAd.OnAdShown += HandleRewardedAdShown;
rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
rewardedAd.OnAdDismissed += HandleRewardedAdDismissed;
rewardedAd.OnAdImpression += HandleImpression;
rewardedAd.OnRewarded += HandleRewarded;

Interstitial ads

The approach to creating and loading advertisements has been revised. There's now an InterstitialAdLoader loader object that handles ad loading and an Interstitial ad object derived from the ad loading OnAdLoaded event .

To learn more about the new API, see the SDK reference.

Loading ads

SDK 5

One object is now used both for loading and serving ads:

private Interstitial interstitial;

private void RequestInterstitial()
{
    string adUnitId = "demo-interstitial-yandex"; // replace with "R-M-XXXXXX-Y"
    interstitial = new Interstitial(adUnitId);

    AdRequest request = new AdRequest.Builder().Build();
    interstitial.LoadAd(request);
}

SDK 6

InterstitialAdLoader loader object for loading multiple ads.

private void SetupLoader()
{
  interstitialAdLoader = new InterstitialAdLoader();
  interstitialAdLoader.OnAdLoaded += HandleInterstitialLoaded;
  interstitialAdLoader.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
}

private void RequestInterstitial()
{
    string adUnitId = "demo-interstitial-yandex"; // replace with "R-M-XXXXXX-Y"
    AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(adUnitId).Build();
    interstitialAdLoader.LoadAd(adRequestConfiguration);
}

Ad serving

SDK 5

Check if the ad is loaded before displaying it.

private void ShowInterstitial()
{
    if (interstitial != null && interstitial.IsLoaded())
    {
        interstitial.Show();
    }
}

SDK 6

You don't need to check whether the ad has been loaded.

private void ShowInterstitial()
{
    if (interstitial != null)
    {
        interstitial.Show();
    }
}

Subscribing to ad lifecycle events

SDK 5

All events come in a single Interstitial object.

interstitial.OnInterstitialLoaded += HandleInterstitialLoaded;
interstitial.OnInterstitialFailedToLoad += HandleInterstitialFailedToLoad;
interstitial.OnReturnedToApplication += HandleReturnedToApplication;
interstitial.OnLeftApplication += HandleLeftApplication;
interstitial.OnAdClicked += HandleAdClicked;
interstitial.OnInterstitialShown += HandleInterstitialShown;
interstitial.OnInterstitialFailedToShow += HandleInterstitialFailedToShow;
interstitial.OnInterstitialDismissed += HandleInterstitialDismissed;
interstitial.OnImpression += HandleImpression;

SDK 6

Ad loading events are received in the InterstitialAdLoader object, and impression events in the Interstitial object. Unified event names. Deleted the OnLeftApplication and OnReturnedToApplication events.

interstitialAdLoader.OnAdLoaded += HandleInterstitialLoaded;
interstitialAdLoader.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
// ...
interstitial.OnAdClicked += HandleAdClicked;
interstitial.OnAdShown += HandleInterstitialShown;
interstitial.OnAdFailedToShow += HandleInterstitialFailedToShow;
interstitial.OnAdDismissed += HandleInterstitialDismissed;
interstitial.OnAdImpression += HandleImpression;

App open ads

Added a new ad format: app open ads. To learn more, see App open ads.

Yandex Mediation

Warning

Be sure to update to the latest adapter versions (Yandex Mediation and adapters for third-party mediation networks). Otherwise, errors from improper adapter integration might occur, preventing the ad from being served.

Renamed the package mobileads-admob-mediation-2.9.0.unitypackage to mobileads-google-mediation-6.0.0.unitypackage.

If you use a unified mediation build, you do not need to do anything. If you're connecting adapters manually, first manually remove the old package and then add the new one.

You can view complete integration examples here: