Skip to content

Interstitial Ads

Loading an Interstitial Ad

The following code shows you how to attach listeners and load the first interstitial ad:

#if UNITY_IOS
string adUnitId = "«iOS-ad-unit-ID»";
#else // UNITY_ANDROID
string adUnitId = "«Android-ad-unit-ID»";
#endif
int retryAttempt;
public void InitializeInterstitialAds()
{
// Attach callback
MaxSdkCallbacks.Interstitial.OnAdLoadedEvent += OnInterstitialLoadedEvent;
MaxSdkCallbacks.Interstitial.OnAdLoadFailedEvent += OnInterstitialLoadFailedEvent;
MaxSdkCallbacks.Interstitial.OnAdDisplayedEvent += OnInterstitialDisplayedEvent;
MaxSdkCallbacks.Interstitial.OnAdClickedEvent += OnInterstitialClickedEvent;
MaxSdkCallbacks.Interstitial.OnAdHiddenEvent += OnInterstitialHiddenEvent;
MaxSdkCallbacks.Interstitial.OnAdDisplayFailedEvent += OnInterstitialAdFailedToDisplayEvent;
// Load the first interstitial
LoadInterstitial();
}
private void LoadInterstitial()
{
MaxSdk.LoadInterstitial(adUnitId);
}
private void OnInterstitialLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Interstitial ad is ready for you to show. MaxSdk.IsInterstitialReady(adUnitId) now returns 'true'
// Reset retry attempt
retryAttempt = 0;
}
private void OnInterstitialLoadFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
{
// Interstitial ad failed to load
// AppLovin recommends that you retry with exponentially higher delays, up to a maximum delay (in this case 64 seconds)
retryAttempt++;
double retryDelay = Math.Pow(2, Math.Min(6, retryAttempt));
Invoke("LoadInterstitial", (float) retryDelay);
}
private void OnInterstitialDisplayedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}
private void OnInterstitialAdFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo, MaxSdkBase.AdInfo adInfo)
{
// Interstitial ad failed to display. AppLovin recommends that you load the next ad.
LoadInterstitial();
}
private void OnInterstitialClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}
private void OnInterstitialHiddenEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
// Interstitial ad is hidden. Pre-load the next ad.
LoadInterstitial();
}

Showing an Interstitial Ad

To show an interstitial ad, call ShowInterstitial():

if ( MaxSdk.IsInterstitialReady(adUnitId) )
{
MaxSdk.ShowInterstitial(adUnitId);
}