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)
#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)
#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)
// 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)
// 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)
private
InterstitialAd
_interstitalAd
;
public
void
ShowInterstitialAd
()
{
if
(
_interstitalAd
!=
null
&&
_interstitalAd
.
CanShowAd
())
{
_interstitalAd
.
Show
();
}
else
{
Debug
.
Log
(
"Interstitial ad cannot be shown."
);
}
}
Version 7 (Legacy)
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)
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)
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
when defining event delegates. In version 8, we adopted 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)
private
BannerView
_bannerView
;
public
void
ConfigureBanner
()
{
_bannerView
.
OnAdPaid
+=
(
AdValue
value
)
=
>
{
AdValue
value
=
value
;
};
}
Version 7 (Legacy)
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
InterstitialAd
RewardedAd
RewardedInterstitialAd
AppOpenAd
AdErrorEventArgs
AdFailedToLoadEventArgs
AdValueEventArgs