Interstitial Ads
Interstitial ads are full-screen or full-page ads that temporarily cover an app’s interface. They’re typically shown at natural pauses or transition points—such as after completing a level in a game or when navigating between major views.
The following sections show you how to load and then show an interstitial ad.
Loading an Interstitial Ad
The following code shows you how to attach listeners and load the first interstitial ad:
#if UNITY_IOSstring adUnitId = "«iOS-ad-unit-ID»";#else // UNITY_ANDROIDstring 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);}