インタースティシャル - 広告ユニットAPIへの移行 - Unity

このガイドでは、現在の実装から LevelPlay インタースティシャル API(広告ユニット ID を使用)へ移行し、インタースティシャル広告をロード・表示する方法について説明します。

Before you start
  • サポートされる最小SDKは8.6.0です。最新の SDK はこちらからダウンロードできます。
  • LevelPlay 初期化 API を使用してSDKを初期化してください。詳細はこちらをご覧ください。
  • AdUnitID は LevelPlay ダッシュボードで確認できます。詳細はこちら

インタースティシャル広告オブジェクトの作成

インタースティシャル広告オブジェクトの作成は、OnInitSuccessコールバックを受け取った後に行う必要があります。

オブジェクトはセッション中に複数回のロードや表示に再利用できます。一度作成したら同じ広告ユニットをロード・表示に使用してください。

より高度な実装が必要な場合は、複数のインタースティシャル広告オブジェクトを作成しても構いません。

// Create interstitial ad object 
interstitialAd = new LevelPlayInterstitialAd(interstitialAdUnitId);

インタースティシャルイベントの登録

広告配信の通知を受けるには、LevelPlayInterstitialAdListener をコードで実装してください。LevelPlayInterstitialListener の代わりに使用します。

  • インタースティシャル広告のロード前にリスナーを設定することを推奨します。
  • 各インタースティシャル広告それぞれにリスナー実装が必要です。
  • コールバックはメインスレッドで実行されます。
// Register to interstitial events
interstitialAd.OnAdLoaded += InterstitialOnAdLoadedEvent;
interstitialAd.OnAdLoadFailed += InterstitialOnAdLoadFailedEvent;
interstitialAd.OnAdDisplayed += InterstitialOnAdDisplayedEvent;
interstitialAd.OnAdDisplayFailed += InterstitialOnAdDisplayFailedEvent;
interstitialAd.OnAdClicked += InterstitialOnAdClickedEvent;
interstitialAd.OnAdClosed += InterstitialOnAdClosedEvent;
interstitialAd.OnAdInfoChanged += InterstitialOnAdInfoChangedEvent;

// Implement the events
void InterstitialOnAdLoadedEvent(LevelPlayAdInfo adInfo){}
void InterstitialOnAdLoadFailedEvent(LevelPlayAdError error){}
void InterstitialOnAdDisplayedEvent(LevelPlayAdInfo adInfo){}
void InterstitialOnAdDisplayFailedEvent(LevelPlayAdDisplayInfoError infoError){}
void InterstitialOnAdClickedEvent(LevelPlayAdInfo adInfo){}
void InterstitialOnAdClosedEvent(LevelPlayAdInfo adInfo){}
void InterstitialOnAdInfoChangedEvent(LevelPlayAdInfo adInfo){}
レガシー 広告ユニット(New)
Listener IronSourceInterstitialEvents LevelPlayInterstitialAdListener
Events OnAdReady OnAdLoaded 
OnAdLoadFailed OnAdLoadFailed
OnAdOpened OnAdDisplayed
OnAdClosed OnAdClosed
OnAdShowFailed OnAdDisplayFailed
OnAdClicked OnAdClicked
OnAdShowSucceeded -(deprecated)
OnAdInfoChanged

LevelPlay Ad Info

Ad Info インタースティシャルリスナーコールバックから返される AdInfo クラスは LevelPlayAdInfo に置き換わりました。

実装や利用可能なフィールドの詳細はこちらをご覧ください。

インタースティシャル広告のロード

インタースティシャル広告をロードするには、LoadInterstitial の代わりにLoadAdを使用してください。

// Load interstitial ad
interstitialAd.LoadAd();

インタースティシャル広告の表示

OnAdLoaded コールバックを受け取った後、LevelPlayInterstitialAdListener API を使ってインタースティシャル広告を表示します。

  • プレースメントを利用する場合は、下記の Placements セクションのように ShowAd API でプレースメント名を渡してください。
  • 広告がユーザーに正常に表示された後は、ロード手順を繰り返して別の広告をロードできます。
// Show ad without placement 
interstitialAd.ShowAd();
// Show ad with placement 
interstitialAd.ShowAd(placementName: "placementName");

広告のロード状態を確認

表示失敗を防ぎ、広告が正しく表示できるよう、ShowAd API 呼び出し前に次の API を使うことを推奨します。

IsAdReady – 広告が正常にロードされ、広告ユニットがキャップされていなければ true、それ以外は false。

IsPlacementCapped – 有効なプレースメントがキャップに達していれば true。無効またはキャップに達していない場合は false。

// Check that ad is ready and that the placement is not capped
if (interstitialAd.IsAdReady() && !LevelPlayInterstitialAd.IsPlacementCapped(placementName))
{ 
    interstitialAd.ShowAd(placementName); 
}

プレースメント

LevelPlay ダッシュボードでインタースティシャル広告のプレースメントのペーシングとキャッピングがサポートされています。

インタースティシャル広告にプレースメントが設定されている場合は、ShowAd メソッドで特定のプレースメントで広告を配信してください。

// Check that ad is ready and that the placement is not capped
if (interstitialAd.IsAdReady() && !LevelPlayInterstitialAd.IsPlacementCapped(placementName))
{ 
    interstitialAd.ShowAd(placementName); 
}

マルチ広告ユニット対応インタースティシャル API

レガシー 広告ユニット(New)
Class IronSource LevelPlayInterstitialAd
API LoadInterstitial LoadAd
ShowInterstitial ShowAd
IsInterstitialPlacementCapped IsPlacementCapped
IsInterstitialReady IsAdReady

インタースティシャル広告のフル実装例

public class InterstitialAdSample {
    private LevelPlayInterstitialAd interstitialAd
    void CreateInterstitialAd() {
	      //Create InterstitialAd instance
        interstitialAd= new LevelPlayInterstitialAd("interstitialAdUnitId");

        //Subscribe InterstitialAd events
        interstitialAd.OnAdLoaded += InterstitialOnAdLoadedEvent;
        interstitialAd.OnAdLoadFailed += InterstitialOnAdLoadFailedEvent;
        interstitialAd.OnAdDisplayed += InterstitialOnAdDisplayedEvent;
        interstitialAd.OnAdDisplayFailed += InterstitialOnAdDisplayFailedEvent;
        interstitialAd.OnAdClicked += InterstitialOnAdClickedEvent;
        interstitialAd.OnAdClosed += InterstitialOnAdClosedEvent;
        interstitialAd.OnAdInfoChanged += InterstitialOnAdInfoChangedEvent;
    }
    void LoadInterstitialAd() {
        //Load or reload InterstitialAd 	
        interstitialAd.LoadAd();
    }
    void ShowInterstitialAd() {
	       //Show InterstitialAd, check if the ad is ready before showing
        if (interstitialAd.IsAdReady()) {
   		      interstitialAd.ShowAd();
        }
    }
    
    void DestroyInterstitialAd() {
	      //Destroy InterstitialAd 
        interstitialAd.DestroyAd();
    }
  
    //Implement InterstitialAd events
    void InterstitialOnAdLoadedEvent(LevelPlayAdInfo adInfo) { }
    void InterstitialOnAdLoadFailedEvent(LevelPlayAdError ironSourceError) { }
    void InterstitialOnAdClickedEvent(LevelPlayAdInfo adInfo) { }
    void InterstitialOnAdDisplayedEvent(LevelPlayAdInfo adInfo) { }
    void InterstitialOnAdDisplayFailedEvent(LevelPlayAdDisplayInfoError adInfoError) { }
    void InterstitialOnAdClosedEvent(LevelPlayAdInfo adInfo) { }
    void InterstitialOnAdInfoChangedEvent(LevelPlayAdInfo adInfo) { }
}

完了!

これで新しいマルチ広告ユニット API を使って、アプリケーション内でインタースティシャル広告を配信できるようになりました。