インタースティシャル

インタースティシャル広告は、ホストアプリのインターフェースを覆うようにフルスクリーンで表示される広告です。 通常、アプリの操作中に画面が自然に切り替わるタイミングで表示されます。 たとえば、ゲームのレベルが切り替わる合間や、次のレベルの一時停止時などにおすすめします。特定の アプリにインタースティシャル広告が表示され、ユーザーは広告をタップするか デスティネーションに移動するか、アプリを閉じてアプリに戻ります。

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

必ずテスト広告でテストする

アプリを作成、テストする際は、テスト広告ではなく、 配信します。実際の広告を使用すると、アカウントが停止される可能性があります。

テスト広告を読み込むには、専用のテスト広告ユニット ID を使用すると、 インタースティシャル:

  • /6499/example/interstitial

テスト広告ユニットは、すべてのリクエストに対してテスト広告を返すように設定されている。 独自のアプリでコーディング、テスト、デバッグを行う際に、自由に使用できます。 必ずご自身の広告ユニット ID に置き換えてください。 。

広告を読み込む

次の例では、インタースティシャル広告を読み込みます。

class InterstitialExampleState extends State<InterstitialExample> {
  AdManagerInterstitialAd? _interstitialAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = '/6499/example/interstitial';

  /// Loads an interstitial ad.
  void loadAd() {
    AdManagerInterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdManagerAdRequest(),
        adLoadCallback: AdManagerInterstitialAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _interstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('AdManagerInterstitialAd failed to load: $error');
          },
        ));
  }
}

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

FullScreenContentCallback を使用すると、ライフサイクルでリッスンし、 イベント(広告が表示されたか閉じたかなど)によって測定されます。セット AdManagerInterstitialAd.fullScreenContentCallback(この広告を表示する前に) 通知を受け取ることができます。この例では、各メソッドを実装します。

class InterstitialExampleState extends State<InterstitialExample> {
  AdManagerInterstitialAd? _interstitialAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = '/6499/example/interstitial';

  /// Loads an interstitial ad.
  void loadAd() {
    AdManagerInterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdManagerAdRequest(),
        adLoadCallback: AdManagerInterstitialAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
             ad.fullScreenContentCallback = FullScreenContentCallback(
                // Called when the ad showed the full screen content.
                onAdShowedFullScreenContent: (ad) {},
                // Called when an impression occurs on the ad.
                onAdImpression: (ad) {},
                // Called when the ad failed to show full screen content.
                onAdFailedToShowFullScreenContent: (ad, err) {
                  // Dispose the ad here to free resources.
                  ad.dispose();
                },
                // Called when the ad dismissed full screen content.
                onAdDismissedFullScreenContent: (ad) {
                  // Dispose the ad here to free resources.
                  ad.dispose();
                },
                // Called when a click is recorded for an ad.
                onAdClicked: (ad) {});

            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _interstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('AdManagerInterstitialAd failed to load: $error');
          },
        ));
  }
}

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

AdManagerInterstitialAdOverlay として表示されます。 すべてのアプリ コンテンツの上に静的に配置されます。そのため ウィジェットツリーで見ていきます広告を表示するタイミングを選択するには、show() を呼び出します。

_interstitiaAd.show();

show() が呼び出されると、このように表示された Ad を閉じることはできません ユーザー入力が必要です。AdManagerInterstitialAdは 1 回だけです。その後の表示の呼び出しは onAdFailedToShowFullScreenContent をトリガーします。

広告にアクセスする必要がなくなったら、広告を破棄する必要があります。ベスト プラクティス dispose() を呼び出すタイミングを FullScreenContentCallback.onAdDismissedFullScreenContentFullScreenContentCallback.onAdFailedToShowFullScreenContent コールバック。

これで、これで、アプリにインタースティシャル広告を表示できるようになりました。

次のステップ