リワード インタースティシャル(ベータ版)

リワード インタースティシャルは、アプリの画面が変わる自然なタイミングで自動的に表示される広告に報酬を提供できる、インセンティブ広告フォーマットの一種です。リワード広告とは異なり、ユーザーはリワード インタースティシャルを表示するためにオプトインする必要はありません。このガイドでは、AdMob のリワード インタースティシャル広告を Flutter アプリに統合する方法について説明します。

前提条件

  • Flutter プラグイン 1.1.0 以降。
  • スタートガイドの手順を踏みます。Flutter アプリには、Google Mobile Ads Flutter プラグインがすでにインポートされているはずです。

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

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

リワード インタースティシャル広告向けのテスト専用広告ユニット ID を使用すると、テスト広告を簡単に読み込むことができます。

Android

ca-app-pub-3940256099942544/5354046379

iOS

ca-app-pub-3940256099942544/6978759866

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

広告を読み込む

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

class RewardedInterstitialExampleState extends State<RewardedInterstitialExample> {
  RewardedInterstitialAd? _rewardeInterstitialdAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/5354046379'
    : 'ca-app-pub-3940256099942544/6978759866';

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

リワード インタースティシャル広告のイベント

FullScreenContentCallback を使用すると、広告の表示や拒否などのライフサイクル イベントをリッスンできます。これらのイベントの通知を受け取るには、広告を表示する前に RewardedInterstitialAd.fullScreenContentCallback を設定します。この例では、各メソッドを実装し、コンソールにメッセージを記録します。

class RewardedInterstitialExampleState extends State<RewardedInterstitialExample> {
  RewardedInterstitialAd? _rewardedInterstitialAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/5354046379'
    : 'ca-app-pub-3940256099942544/6978759866';

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedInterstitialAd.load(
        adUnitId: adUnitId,
        adRequest: const AdRequest(),
        adLoadCallback: RewardedInterstitialAdLoadCallback(
          // 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.
            _rewardedInterstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugprint('RewardedInterstitialAd failed to load: $error');
          },
        ));
  }
}

ディスプレイ広告

RewardedInterstitialAd は、すべてのアプリ コンテンツの上にオーバーレイとして表示され、静的に配置されます。そのため、Flutter ウィジェット ツリーには追加できません。広告を表示するタイミングを選択するには、show() を呼び出します。 RewardedInterstitialAd.show()OnUserEarnedRewardCallback を受け取ります。これはユーザーが特典を獲得したときに呼び出されます。これを実装して、広告を視聴したユーザーに報酬を付与しましょう。

_rewardedInterstitialAd.show(onUserEarnedReward: (AdWithoutView ad, RewardItem rewardItem) {
  // Reward the user for watching an ad.
});

show() が呼び出されると、この方法で表示された Ad をプログラムで削除することはできず、ユーザー入力が必要になります。RewardedInterstitialAd は 1 回だけ表示できます。その後の show の呼び出しは、onAdFailedToShowFullScreenContent をトリガーします。

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

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

GitHub 上のサンプル全体

リワード インタースティシャル