<br />

Last updated: February 2023

This page covers migrations for current and previous versions.

## Migrate from version 7 to version 8

### Full Screen formats now use a static load method

In version 7 of the plugin, interstitial and rewarded ads had an instance level
`LoadAd()` method for loading an ad whereas rewarded interstitial ad and app
open ads had a static `Load()` method for loading ads. In version 8, all full
screen ad formats (interstitial, rewarded, rewarded interstitial, and app open)
will have a static `Load()` method for loading ads. Here is an example of how
to load an interstitial ad:

### Version 8 (Current)

```c#
#if UNITY_ANDROID
const string adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
const string adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
const string adUnitId = "unexpected_platform";
#endif

private InterstitialAd _interstitialAd;

private void LoadAd()
{
    // Load an interstitial ad
    InterstitialAd.Load(adUnitId, new AdRequest(),
        (InterstitialAd ad, LoadAdError loadAdError) =>
        {
            if (loadAdError != null)
            {
                Debug.Log("Interstitial ad failed to load with error: " +
                           loadAdError.GetMessage());
                return;
            }
            else if (ad == null)
            {
                Debug.Log("Interstitial ad failed to load.");
                return;
            }

            Debug.Log("Interstitial ad loaded.");
            _interstitialAd = ad;
        });
}
```

### Version 7 (Legacy)

```c#
#if UNITY_ANDROID
const string adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
const string adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
const string adUnitId = "unexpected_platform";
#endif

private InterstitialAd _interstitialAd;

private void LoadInterstitialAd()
{
    // Initialize an InterstitialAd.
    _interstitialAd = new InterstitialAd(adUnitId);
    // Called when an ad request has successfully loaded.
    _interstitialAd.OnAdLoaded += HandleOnAdLoaded;
    // Called when an ad request has failed to load.
    _interstitialAd.OnAdFailedToLoad += HandleOnAdFailedToLoad;
    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the interstitial with the request.
    _interstitialAd.LoadAd(request);
}

private void HandleOnAdLoaded(object sender, EventArgs args)
{
    Debug.Log("Interstitial ad loaded.");
}

private void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    if (args != null)
    {
        Debug.Log("Interstitial ad failed to load with error: " +
                   args.LoadAdError.GetMessage());
    }
}
```

Here is an example of how to load a rewarded ad:

### Version 8 (Current)

```c#
// These ad units are configured to always serve test ads.
#if UNITY_ANDROID
const string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
const string adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
const string adUnitId = "unused";
#endif

private RewardedAd _rewardedAd;

private void LoadRewardedAd()
{
    // Load a rewarded ad
    RewardedAd.Load(adUnitId, new AdRequest(),
        (Rewarded ad, LoadAdError loadError) =>
        {
            if (loadError != null)
            {
                Debug.Log("Rewarded ad failed to load with error: " +
                           loadError.GetMessage());
                return;
            }
            else if (ad == null)
            {
                Debug.Log("Rewarded ad failed to load.");
                    return;
            }

            Debug.Log("Rewarded ad loaded.");
            _rewardedAd = ad;
        });
}
```

### Version 7 (Legacy)

```c#
// These ad units are configured to always serve test ads.
#if UNITY_ANDROID
const string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
const string adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
const string adUnitId = "unused";
#endif

private RewardedAd _rewardedAd;

private void LoadRewardedAd()
{
    // Initialize an InterstitialAd.
    _rewardedAd = new RewardedAd(adUnitId);
    // Called when an ad request has successfully loaded.
    _rewardedAd.OnAdLoaded += HandleOnAdLoaded;
    // Called when an ad request has failed to load.
    _rewardedAd.OnAdFailedToLoad += HandleOnAdFailedToLoad;
    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the interstitial with the request.
    _rewardedAd.LoadAd(request);
}

private void HandleOnAdLoaded(object sender, EventArgs args)
{
    Debug.Log("Rewarded ad loaded.");
}

private void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    if (args != null)
    {
        Debug.Log("Rewarded ad failed to load with error: " +
                   args.LoadAdError.GetMessage());
    }
}
```

### Use CanShowAd() to check for readiness in showing full-screen ads

In version 7, full-screen ads (interstitial, rewarded, rewarded interstitial,
and app open ads) had the `IsLoaded()` method which returns `true` if the ad was
loaded. Due to the change in how ads are loaded, in version 8 you don't have
access to the full-screen ad object until the ad is loaded, making the
`IsLoaded()` method obsolete.

Version 8 has a new method named `CanShowAd()` that returns `true` if the ad
can still be shown. Here is an example of how to use `CanShowAd()` on an
interstitial ad:

### Version 8 (Current)

```c#
private InterstitialAd _interstitalAd;

public void ShowInterstitialAd()
{
    if (_interstitalAd != null && _interstitalAd.CanShowAd())
    {
        _interstitalAd.Show();
    }
    else
    {
        Debug.Log("Interstitial ad cannot be shown.");
    }
}

```

### Version 7 (Legacy)

```c#
private InterstitialAd _interstitalAd;

public void ShowInterstitialAd()
{
    if (_interstitalAd != null && _interstitalAd.IsLoaded())
    {
        _interstitalAd.Show();
    }
    else
    {
        Debug.Log("Interstitial ad is not ready yet.");
    }
}
```

### Use Show(Action) to show rewarded ads

In version 7 of the plugin, rewarded ads had the `Show()` method with a separate
`OnUserEarnedReward` event for handling the user reward signals, and the
rewarded interstitial ad had a `Show(Action<Reward>)` method with a callback for
handling the user reward signal. In version 8, rewarded and rewarded
interstitial ad formats will have a `Show(Action<Reward>)` method with a
callback for handling the user reward notification.

Here is an example of how to show a rewarded ad:

### Version 8 (Current)

```c#
private RewardedAd _rewardedAd;

public void ShowRewardedAd()
{
    if (_rewardedAd != null && _rewardedAd.CanShowAd())
    {
        _rewardedAd.Show((Reward reward) =>
        {
            Debug.Log("Rewarded ad granted a reward: " +
                    reward.Amount);
        });
    }
    else
    {
        Debug.Log("Rewarded ad cannot be shown.");
    }
}

```

### Version 7 (Legacy)

```c#
private RewardedAd _rewardedAd;

public void ShowRewardedAd()
{
    if (_rewardedAd != null && _rewardedAd.CanShowAd())
    {
        _rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
        _rewardedAd.Show();
    }
    else
    {
        Debug.Log("Rewarded ad is not ready yet.");
    }
}
public void HandleUserEarnedReward(object sender, Reward reward)
{
    Debug.Log("Rewarded ad granted a reward: " +
               reward.Amount);
}
```

### Ad event delegates now adopt specific type arguments

In version 7 of the API, we made use of
[`EventHandlers`](https://learn.microsoft.com/en-us/dotnet/api/system.eventhandler-1?view=net-7.0)
when defining event delegates. In version 8, we adopted [generic
delegates](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-delegates)
for ad events. As a result, events will now emit event values directly without
being wrapped in the `EventArg` class.

Here is an example of using `OnAdPaid` (in place of `OnPaidEvent`):

### Version 8 (Current)

```c#
private BannerView _bannerView;

public void ConfigureBanner()
{
    _bannerView.OnAdPaid += (AdValue value) =\>
    {
        AdValue value = value;
    };
}
```

### Version 7 (Legacy)

```c#
private BannerView _bannerView;

public void ConfigureBanner()
{
    _bannerView.OnPaidEvent += (object sender, AdValueEventArg arg) =>
    {
        AdValue value = arg.Value;
    };
}
```

### Ad formats now conform to a uniform interface

In version 7 of the plugin, there were discrepancies in the event names between
full-screen ad formats. In version 8, we have renamed many of our API methods to
be consistent across our ad formats.

The following table lists the class changes introduced in v8.

| `BannerView` ||
| v7 | v8 |
|---|---|
| OnAdLoaded | [OnBannerAdLoaded](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/banner-view.md.txt#onbanneradloaded) |
| OnAdFailedToLoad | [OnBannerAdLoadFailed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/banner-view.md.txt#onbanneradloadfailed) |
| OnAdOpening | [OnAdFullScreenContentOpened](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/banner-view.md.txt#onadfullscreencontentopened) |
| OnAdClosed | [OnAdFullScreenContentClosed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/banner-view.md.txt#onadfullscreencontentclosed) |
| OnPaidEvent | [OnAdPaid](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/banner-view.md.txt#onadpaid) |
| LoadAd() | [InterstitialAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#load) |
| InterstitialAd() | [InterstitialAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#load) |
| OnAdLoaded | [InterstitialAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#load) |
| OnAdFailedToLoad | [InterstitialAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#load) |
| OnAdOpening | [OnAdFullScreenContentOpened](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#onadfullscreencontentopened) |
| OnAdClosed | [OnAdFullScreenContentClosed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#onadfullscreencontentclosed) |
| OnAdFailedToShow | [OnAdFullScreenContentFailed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#onadfullscreencontentfailed) |
| OnAdDidRecordImpression | [OnAdImpressionRecorded](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#onadimpressionrecorded) |
| OnPaidEvent | [OnAdPaid](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/interstitial-ad.md.txt#onadpaid) |
| LoadAd() | [RewardedAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#load) |
| RewardedAd() | [RewardedAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#load) |
| OnAdLoaded | [RewardedAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#load) |
| OnAdFailedToLoad | [RewardedAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#load) |
| OnAdOpening | [OnAdFullScreenContentOpened](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#onadfullscreencontentopened) |
| OnAdClosed | [OnAdFullScreenContentClosed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#onadfullscreencontentclosed) |
| OnAdFailedToShow | [OnAdFullScreenContentFailed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#onadfullscreencontentfailed) |
| OnAdDidRecordImpression | [OnAdImpressionRecorded](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#onadimpressionrecorded) |
| OnPaidEvent | [OnAdPaid](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#onadpaid) |
| Show() | [Show()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#show) |
| OnUserEarnedReward | [Show()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-ad.md.txt#show) |
| LoadAd() | [RewardedInterstitialAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-interstitial-ad.md.txt#load) |
| OnPaidEvent | [OnAdPaid](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-interstitial-ad.md.txt#onadpaid) |
| OnAdDidPresentFullScreenContent | [OnAdFullScreenContentOpened](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-interstitial-ad.md.txt#onadfullscreencontentopened) |
| OnAdDidDismissFullScreenContent | [OnAdFullScreenContentClosed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-interstitial-ad.md.txt#onadfullscreencontentclosed) |
| OnAdFailedToPresentFullScreenContent | [OnAdFullScreenContentFailed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-interstitial-ad.md.txt#onadfullscreencontentfailed) |
| OnAdDidRecordImpression | [OnAdImpressionRecorded](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/rewarded-interstitial-ad.md.txt#onadimpressionrecorded) |
| LoadAd() | [AppOpenAd.Load()](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/app-open-ad.md.txt#load) |
| OnPaidEvent | [OnAdPaid](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/app-open-ad.md.txt#onadpaid) |
| OnAdDidPresentFullScreenContent | [OnAdFullScreenContentOpened](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/app-open-ad.md.txt#onadfullscreencontentopened) |
| OnAdDidDismissFullScreenContent | [OnAdFullScreenContentClosed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/app-open-ad.md.txt#onadfullscreencontentclosed) |
| OnAdFailedToPresentFullScreenContent | [OnAdFullScreenContentFailed](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/app-open-ad.md.txt#onadfullscreencontentfailed) |
| OnAdDidRecordImpression | [OnAdImpressionRecorded](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/app-open-ad.md.txt#onadimpressionrecorded) |
| AdErrorEventArgs.AdError | Use [AdError](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/ad-error.md.txt) directly. |
| AdFailedToLoadEventArgs.LoadAdError | Use [LoadAdError](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/load-ad-error.md.txt) directly. |
| AdValueEventArgs.AdValue | Use [AdValue](https://developers.google.com/admob/unity/reference/class/google-mobile-ads/api/ad-value.md.txt) directly. |