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

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

前提条件

  • 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 コールバック。

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