Межстраничные объявления с вознаграждением

Выберите платформу: Android iOS Unity Flutter Android (Legacy)

Rewarded interstitial is a type of incentivized ad format that lets you offer rewards for ads that appear automatically during natural app transitions. Unlike rewarded ads, users aren't required to opt-in to view a rewarded interstitial. This guide shows how to integrate rewarded interstitial ads from AdMob into a Flutter app.

Предварительные требования

Прежде чем продолжить, выполните следующие действия:

  • Установите плагин Flutter версии 1.1.0 или выше.
  • Настройте Google Mobile Ads Flutter Plugin . В вашем приложении Flutter должен быть импортирован Google Mobile Ads Flutter Plugin .

Всегда проводите тестирование с помощью тестовых объявлений.

При разработке и тестировании приложений обязательно используйте тестовые объявления, а не реальные, рабочие объявления. Несоблюдение этого правила может привести к блокировке вашего аккаунта.

Самый простой способ загрузить тестовые объявления — использовать наш специальный идентификатор тестового рекламного блока для межстраничных объявлений с вознаграждением:

Android

ca-app-pub-3940256099942544/5354046379

iOS

ca-app-pub-3940256099942544/6978759866

The test ad units are configured to return test ads for every request, and you're free to use them in your own apps while coding, testing, and debugging. Just make sure you replace them with your own ad unit IDs before publishing your app.

Загрузить рекламу

В следующем примере загружается рекламное объявление с вознаграждением:

RewardedInterstitialAd.load(
  adUnitId: "_adUnitId",
  request: const AdRequest(),
  rewardedInterstitialAdLoadCallback: RewardedInterstitialAdLoadCallback(
    onAdLoaded: (RewardedInterstitialAd ad) {
      // Called when an ad is successfully received.
      debugPrint('Ad was loaded.');
      // Keep a reference to the ad so you can show it later.
      _rewardedInterstitialAd = ad;
    },
    onAdFailedToLoad: (LoadAdError error) {
      // Called when an ad request failed.
      debugPrint('Ad failed to load with error: $error');
    },
  ),
);

Замените _adUnitId на идентификатор вашего рекламного блока.

Рекламные мероприятия в межстраничной области с вознаграждением

Through the use of FullScreenContentCallback , you can listen for lifecycle events, such as when the ad is shown or dismissed. Set RewardedInterstitialAd.fullScreenContentCallback before showing the ad to receive notifications for these events. This example implements each method and logs a message to the console:

ad.fullScreenContentCallback = FullScreenContentCallback(
  onAdShowedFullScreenContent: (ad) {
    // Called when the ad showed the full screen content.
    debugPrint('Ad showed full screen content.');
  },
  onAdFailedToShowFullScreenContent: (ad, err) {
    // Called when the ad failed to show full screen content.
    debugPrint('Ad failed to show full screen content with error: $err');
    // Dispose the ad here to free resources.
    ad.dispose();
  },
  onAdDismissedFullScreenContent: (ad) {
    // Called when the ad dismissed full screen content.
    debugPrint('Ad was dismissed.');
    // Dispose the ad here to free resources.
    ad.dispose();
  },
  onAdImpression: (ad) {
    // Called when an impression occurs on the ad.
    debugPrint('Ad recorded an impression.');
  },
  onAdClicked: (ad) {
    // Called when a click is recorded for an ad.
    debugPrint('Ad was clicked.');
  },
);

Показывать рекламу

A RewardedInterstitialAd is displayed as an Overlay on top of all app content and is statically placed; thus, it can't be added to the Flutter widget tree. You can choose when to show the ad by calling show() . RewardedInterstitialAd.show() takes an OnUserEarnedRewardCallback , which is invoked when the user earns a reward. Be sure to implement this and reward the user for watching an ad.

_rewardedInterstitialAd?.show(
  onUserEarnedReward: (AdWithoutView view, RewardItem rewardItem) {
    debugPrint('Reward amount: ${rewardItem.amount}');
  },
);

Once show() is called, an Ad displayed this way can't be removed programmatically and requires user input. A RewardedInterstitialAd can only be shown once. Subsequent calls to show will trigger onAdFailedToShowFullScreenContent .

An ad must be disposed when access to it is no longer needed. The best practice for when to call dispose() is in the FullScreenContentCallback.onAdDismissedFullScreenContent and FullScreenContentCallback.onAdFailedToShowFullScreenContent callbacks.

[Необязательно] Проверка обратных вызовов серверной проверки (SSV)

Apps that require extra data in server-side verification callbacks should use the custom data feature of rewarded ads. Any string value set on a rewarded ad object is passed to the custom_data query parameter of the SSV callback. If no custom data value is set, the custom_data query parameter value won't be present in the SSV callback.

Приведенный ниже пример кода демонстрирует, как установить параметры SSV после загрузки рекламного объявления с вознаграждением:

RewardedInterstitialAd.load(
  adUnitId: "_adUnitId",
  request: AdRequest(),
  rewardedInterstitialAdLoadCallback: RewardedInterstitialAdLoadCallback(
    onAdLoaded: (ad) {
      ServerSideVerificationOptions _options =
          ServerSideVerificationOptions(
            customData: 'SAMPLE_CUSTOM_DATA_STRING',
          );
      ad.setServerSideOptions(_options);
      _rewardedInterstitialAd = ad;
    },
    onAdFailedToLoad: (error) {},
  ),
);

Замените SAMPLE_CUSTOM_DATA_STRING на ваши пользовательские данные.

Полный пример на GitHub

Вознагражденный интерстициальный