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

リワード インタースティシャルは、インセンティブ広告フォーマットの一種で、 報酬 自動的に最適化されます。リワード広告とは異なり、ユーザーはリワード インタースティシャルを表示するためにオプトインする必要はありません。このガイドでは、 AdMob のリワード インタースティシャル広告を組み込む 実装する方法も学習しました

前提条件

  • Flutter プラグイン 1.1.0 以降。
  • スタートガイドの手順を踏みます。Flutter アプリに Google モバイル広告の 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 度しか表示できません。その後の表示の呼び出しはトリガーされます onAdFailedToShowFullScreenContent

広告にアクセスする必要がなくなったら、広告を破棄する必要があります。dispose() を呼び出すおすすめのタイミングは、FullScreenContentCallback.onAdDismissedFullScreenContent および FullScreenContentCallback.onAdFailedToShowFullScreenContent のコールバック時です。

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

GitHub 上のサンプル全体

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