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

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

前提条件

  • Flutter プラグイン 1.1.0 以降。
  • スタートガイドの手順を完了し、お客様の Flutter アプリに Google Mobile Ads Flutter プラグインがすでにインストールされている 表示されます。

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

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

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

  • /21775744923/example/rewarded-interstitial

テスト広告ユニットはすべてのリクエストに対してテスト広告を返す特別な広告ユニットで、アプリのコーディング、テスト、デバッグで自由に使うことができます。公開する前に、必ずご自身の広告ユニット ID に置き換えてください 説明します。

広告を読み込む

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

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

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

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedInterstitialAd.loadWithAdManagerAdRequest(
        adUnitId: adUnitId,
        adManagerAdRequest: const AdManagerAdRequest(),
        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 = '/21775744923/example/rewarded-interstitial';

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedInterstitialAd.loadWithAdManagerAdRequest(
        adUnitId: adUnitId,
        adManagerAdRequest: const AdManagerAdRequest(),
        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.onAdDismissedFullScreenContentFullScreenContentCallback.onAdFailedToShowFullScreenContent コールバック。

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