Interstitial Ads

Loading an Interstitial Ad

The following code shows you how to bind to delegates and load the first interstitial:

  • Initialize Interstitial Ads. Custom Event. Interstitial ad is ready to be shown. “Is Interstitial Ready” will return true. On Interstitial Ad Loaded Dynamic Delegate (AppLovinMAXDelegate): Ad Info. Reset retry attempts. SET. Retry Attempt: 0.0. On Interstitial Ad Load Failed Dynamic Delegate (AppLovinMAXDelegate): Ad Info, Ad Error. Retry Attempt. ++. MIN: 6.0, Add pin +. Power: Base 2.0, Exp, Return Value. Delay: Duration, Completed. If interstitial ad fails to load, retry with exponentially higher delays up to a maximum delay (in this case 64 seconds). Interstitial ad failed to display. AppLovin recommends loading the next ad. On Interstitial Ad Display Failed Dynamic Delegate (AppLovinMAXDelegate): Ad Info, Ad Error. Interstitial ad is hidden. Pre-load the next ad. On Interstitial Ad Hidden Dynamic Delegate (AppLovinMAXDelegate): Ad Info. Ad Unit Identifier. Load Interstitial: Ad Unit Identifier.
  • // UMyWidget.cpp (UMyWidget inherits from UObject to access TimerManager)
    
    #include "UMyWidget.h"
    #include "AppLovinMAX.h"
    
    // For retry timer logic
    #include "Async/Async.h"
    #include "Engine/World.h"
    #include "TimerManager.h"
    
    const FString InterstitialAdUnitId = TEXT("ad_unit_ID");
    int RetryAttempt = 0;
    FTimerHandle LoadTimerHandle;
    
    void UMyWidget::InitializeInterstitialAds()
    {
      // Bind member functions to delegates
      UAppLovinMAX::OnInterstitialAdLoadedDelegate.AddUObject(this, &UMyWidget::OnInterstitialAdLoaded);
      UAppLovinMAX::OnInterstitialAdLoadFailedDelegate.AddUObject(this, &UMyWidget::OnInterstitialAdLoadFailed);
      UAppLovinMAX::OnInterstitialAdDisplayFailedDelegate.AddUObject(this, &UMyWidget::OnInterstitialAdDisplayFailed);
      UAppLovinMAX::OnInterstitialAdHiddenDelegate.AddUObject(this, &UMyWidget::OnInterstitialAdHidden);
        
      // Load first interstitial
      LoadInterstitial();
    }
    
    void UMyWidget::LoadInterstitial()
    {
      UAppLovinMAX::LoadInterstitial(InterstitialAdUnitId);
    }
    
    void UMyWidget::OnInterstitialAdLoaded(const FAdInfo &Aamp;dInfo)
    {
      // Interstitial ad is ready to be shown. UAppLovinMAX::IsInterstitialReady(InterstitialAdUnitId) will now return 'true'
    
      // Reset retry attempt
      RetryAttempt = 0;
    }
    
    void UMyWidget::OnInterstitialAdLoadFailed(const FAdInfo &AdInfo, const FAdError &AdError)
    {
      // 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++;
      AsyncTask(ENamedThreads::GameThread, [this]() {           
        float RetryDelay = FMath::Pow(2.0f, FMath::Min(6, RetryAttempt));
        GetWorld()->GetTimerManager().SetTimer(LoadTimerHandle, this, &UMyWidget::LoadInterstitial, RetryDelay, false);
      });
    }
    
    void UMyWidget::OnInterstitialAdDisplayFailed(const FAdInfo &AdInfo, const FAdError &AdError)
    {
      // Interstitial ad failed to display. AppLovin recommends that you load the next ad.
      LoadInterstitial();
    }
    
    void UMyWidget::OnInterstitialAdHidden(const FAdInfo &AdInfo)
    {
      // Interstitial ad is hidden. Pre-load the next ad.
      LoadInterstitial();
    }

Showing an Interstitial Ad

To show an interstitial ad, call ShowInterstitial():

  • Ad Unit Identifier. Is Interstitial Ready: Ad Unit Identifier, Return Value. Branch: Condition, True/False. Show Interstitial: Ad Unit Identifier, Placement.
  • if (UAppLovinMAX::IsInterstitialReady(InterstitialAdUnitId))
    {
      UAppLovinMAX::ShowInterstitial(InterstitialAdUnitId);
    }