插頁式獎勵廣告 (Beta 版)

插頁式獎勵廣告是一種獎勵廣告格式 獎勵 自動在應用程式的自然轉換期間自動切換。有別於獎勵廣告 必須啟用才能觀看插頁式獎勵廣告。本指南說明如何 整合 Ad Manager 的插頁式獎勵廣告 移至 Flutter 應用程式

先備知識

  • Flutter 外掛程式 1.1.0 以上版本。
  • 完成開始使用。您的 Flutter 應用程式應該已安裝 Google Mobile Ads Flutter 外掛程式 已匯入。

一律使用測試廣告進行測試

建構及測試應用程式時,請務必使用測試廣告,而非 現場及正式環境廣告否則可能導致帳戶遭到停權。

要載入測試廣告,最簡單的方法是使用我們專屬的測試廣告單元編號。 插頁式獎勵廣告:

  • /21775744923/example/rewarded_interstitial

測試廣告單元會設為針對每個請求傳回測試廣告。 您可以在自己的應用程式中使用這些 API,編寫程式碼、測試及偵錯。 發布前,請確實將這些內容換成自己的廣告單元編號

載入廣告

以下範例會載入插頁式獎勵廣告:

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 只能 只會顯示一次後續要顯示的通話會觸發 onAdFailedToShowFullScreenContent

不再需要放送的廣告時,必須予以處理。最佳做法 何時該呼叫 dispose() 位於 「FullScreenContentCallback.onAdDismissedFullScreenContent」和 FullScreenContentCallback.onAdFailedToShowFullScreenContent 回呼。

大功告成!您的應用程式現在可以顯示插頁式獎勵廣告了。