インタースティシャル広告
インタースティシャル広告は、アプリのインターフェイスを一時的に覆う、フル画面またはフルページ広告です。 この広告は、一般的に、ゲームのレベル完了後や主要な画面間の遷移時など、アプリ内の自然な区切りや遷移ポイントで表示されます。
次のセクションでは、インタースティシャル広告をロードし、表示する方法について説明します。
インタースティシャル広告をロード
以下のコードは、デリゲートにバインドして最初のインタースティシャル広告をロードする方法を示しています。
// 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 &AdInfo){ // 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();}
インタースティシャル広告を表示
インタースティシャル広告を表示するには、ShowInterstitial()
を呼び出します。
if (UAppLovinMAX::IsInterstitialReady(InterstitialAdUnitId)){ UAppLovinMAX::ShowInterstitial(InterstitialAdUnitId);}