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

インタースティシャル広告は、ホストアプリのインターフェース上に表示されるフルスクリーン広告です。通常は、ゲームレベルをクリアした後の合間など、アプリの操作中に画面が切り替わるタイミングで表示されます。アプリにインタースティシャル広告が表示されると、ユーザーは広告をタップしてリンク先に移動するか、広告を閉じてアプリに戻るかを選択できます。 事例紹介

このガイドでは、インタースティシャル広告を Unity アプリに組み込む方法について説明します。

前提条件

Always test with test ads

The following sample code contains an ad unit ID which you can use to request test ads. It's been specially configured to return test ads rather than production ads for every request, making it safe to use.

However, after you've registered an app in the AdMob web interface and created your own ad unit IDs for use in your app, explicitly configure your device as a test device during development.

Android

ca-app-pub-3940256099942544/1033173712

iOS

ca-app-pub-3940256099942544/4411468910

Initialize the Mobile Ads SDK

Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.Initialize(). This needs to be done only once, ideally at app launch.

using GoogleMobileAds;
using GoogleMobileAds.Api;

public class GoogleMobileAdsDemoScript : MonoBehaviour
{
    public void Start()
    {
        // Initialize the Google Mobile Ads SDK.
        MobileAds.Initialize((InitializationStatus initStatus) =>
        {
            // This callback is called once the MobileAds SDK is initialized.
        });
    }
}

If you're using mediation, wait until the callback occurs before loading ads as this will ensure that all mediation adapters are initialized.

実装

インタースティシャル広告を組み込む主な手順は、以下のとおりです。

  1. インタースティシャル広告を読み込む
  2. インタースティシャル広告を表示する
  3. インタースティシャル広告のイベントをリッスンする
  4. インタースティシャル広告をクリーンアップする
  5. 次のインタースティシャル広告をプリロードする

インタースティシャル広告を読み込む

インタースティシャル広告の読み込みは、InterstitialAd クラスで静的 Load() メソッドを使用して行います。読み込みメソッドには、広告ユニット ID と AdRequest オブジェクトのほか、広告の読み込みの成功時または失敗時に呼び出される完了ハンドラが必要です。読み込まれた InterstitialAd オブジェクトは、完了ハンドラのパラメータとして提供されます。以下の例は、InterstitialAd を読み込む方法を示しています。


  // These ad units are configured to always serve test ads.
#if UNITY_ANDROID
  private string _adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
  private string _adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
  private string _adUnitId = "unused";
#endif

  private InterstitialAd _interstitialAd;

  /// <summary>
  /// Loads the interstitial ad.
  /// </summary>
  public void LoadInterstitialAd()
  {
      // Clean up the old ad before loading a new one.
      if (_interstitialAd != null)
      {
            _interstitialAd.Destroy();
            _interstitialAd = null;
      }

      Debug.Log("Loading the interstitial ad.");

      // create our request used to load the ad.
      var adRequest = new AdRequest();

      // send the request to load the ad.
      InterstitialAd.Load(_adUnitId, adRequest,
          (InterstitialAd ad, LoadAdError error) =>
          {
              // if error is not null, the load request failed.
              if (error != null || ad == null)
              {
                  Debug.LogError("interstitial ad failed to load an ad " +
                                 "with error : " + error);
                  return;
              }

              Debug.Log("Interstitial ad loaded with response : "
                        + ad.GetResponseInfo());

              _interstitialAd = ad;
          });
  }

インタースティシャル広告を表示する

読み込まれたインタースティシャル広告を表示するには、InterstitialAd インスタンスで Show() メソッドを呼び出します。読み込んだ広告は 1 回だけ表示できます。CanShowAd() メソッドを使用して、広告を表示する準備ができていることを確認します。

/// <summary>
/// Shows the interstitial ad.
/// </summary>
public void ShowInterstitialAd()
{
    if (_interstitialAd != null && _interstitialAd.CanShowAd())
    {
        Debug.Log("Showing interstitial ad.");
        _interstitialAd.Show();
    }
    else
    {
        Debug.LogError("Interstitial ad is not ready yet.");
    }
}

インタースティシャル広告のイベントをリッスンする

広告の動作をさらにカスタマイズするには、広告のライフサイクルで生じるさまざまなイベントを利用します。これらのイベントをリッスンするには、以下のようにデリゲートを登録します。

private void RegisterEventHandlers(InterstitialAd interstitialAd)
{
    // Raised when the ad is estimated to have earned money.
    interstitialAd.OnAdPaid += (AdValue adValue) =>
    {
        Debug.Log(String.Format("Interstitial ad paid {0} {1}.",
            adValue.Value,
            adValue.CurrencyCode));
    };
    // Raised when an impression is recorded for an ad.
    interstitialAd.OnAdImpressionRecorded += () =>
    {
        Debug.Log("Interstitial ad recorded an impression.");
    };
    // Raised when a click is recorded for an ad.
    interstitialAd.OnAdClicked += () =>
    {
        Debug.Log("Interstitial ad was clicked.");
    };
    // Raised when an ad opened full screen content.
    interstitialAd.OnAdFullScreenContentOpened += () =>
    {
        Debug.Log("Interstitial ad full screen content opened.");
    };
    // Raised when the ad closed full screen content.
    interstitialAd.OnAdFullScreenContentClosed += () =>
    {
        Debug.Log("Interstitial ad full screen content closed.");
    };
    // Raised when the ad failed to open full screen content.
    interstitialAd.OnAdFullScreenContentFailed += (AdError error) =>
    {
        Debug.LogError("Interstitial ad failed to open full screen content " +
                       "with error : " + error);
    };
}

インタースティシャル広告をクリーンアップする

使い終わった InterstitialAd への参照を破棄する前に、必ず Destroy() メソッドを呼び出してください。

_interstitialAd.Destroy();

これにより、そのオブジェクトはもう使用されておらず、オブジェクトが占有していたメモリを回収しても問題ないことを、プラグインに通知できます。このメソッドを呼び出さないとメモリリークが発生します。

次のインタースティシャル広告をプリロードする

インタースティシャル広告は使い捨てオブジェクトです。一度インタースティシャル広告を表示した後、同じオブジェクトを再度使うことはできません。さらにインタースティシャル広告をリクエストするには、新しい InterstitialAd オブジェクトを作成します。

次のインプレッションの機会に備えてインタースティシャル広告を用意するには、広告イベント OnAdFullScreenContentClosed または OnAdFullScreenContentFailed が発生した時点でインタースティシャル広告をプリロードするようにします。

private void RegisterReloadHandler(InterstitialAd interstitialAd)
{
    // Raised when the ad closed full screen content.
    interstitialAd.OnAdFullScreenContentClosed += ()
    {
        Debug.Log("Interstitial Ad full screen content closed.");

        // Reload the ad so that we can show another as soon as possible.
        LoadInterstitialAd();
    };
    // Raised when the ad failed to open full screen content.
    interstitialAd.OnAdFullScreenContentFailed += (AdError error) =>
    {
        Debug.LogError("Interstitial ad failed to open full screen content " +
                       "with error : " + error);

        // Reload the ad so that we can show another as soon as possible.
        LoadInterstitialAd();
    };
}

ベスト プラクティス

インタースティシャル広告がアプリに適しているかどうかを判断します。
インタースティシャル広告は、自然な移行ポイント(画面の切り替わりなど)があるアプリに最適です。 画像の共有やゲームレベルのクリアなど、アプリ内で特定のタスクが完了したタイミングがこうした移行ポイントになります。アプリのフローの中で、インタースティシャル広告の表示に最適なタイミングと、ユーザーがそれにどう反応する可能性が高いかを検討しましょう。
インタースティシャル広告を表示する際にアクションを一時停止する。
インタースティシャル広告には、テキスト、イメージ、動画などさまざまな種類があります。アプリでインタースティシャル広告を表示する際に、一部のリソースの使用を一時停止して、広告がそれらのリソースを利用できるようにする必要があります。たとえば、インタースティシャル広告を表示するための呼び出しを行うときは、アプリが生成している音声出力を一時停止するようにしてください。音声再生は OnAdFullScreenContentClosed() イベントで再開できます。このイベントは、ユーザーが広告の操作を終了したときに呼び出すことができます。また、広告の表示中は、ゲームループなどの負荷の高い計算処理を一時的に停止することも検討してください。これにより、グラフィックが遅い、反応しない、動画がスムーズに再生されないといった問題を回避できます。
過度に広告を表示しないよう注意しましょう。
インタースティシャル広告の表示頻度を上げることは、収益向上の手段としては魅力的に思えるかもしれませんが、同時に、ユーザー エクスペリエンスの低下やクリック率の低下にもつながります。ユーザーがアプリを楽しめなくなるほど頻繁に広告を表示することがないようにしてください。

参考情報

* ユースケースの例