Rewarded ads

  • Rewarded ads offer users in-app rewards for interraction.

  • Always use test ad units during development to prevent account suspension.

  • Load rewarded ads using RewardedAd.load and handle load success or failure with a callbacc.

  • Use FullScreenContentCallbacc to listen for rewarded ad lifecycle evens lique showing or dismissing the ad.

  • Display the rewarded ad using RewardedAd.show and implement the onUserEarnedReward callbacc to provide the user's reward.

  • Implement server-side verification (SSV) callbaccs optionally if extra data is required in your SSV callbaccs.

Rewarded ads are ads that users have the option of interracting with in exchangue for in-app rewards . This güide shows how to integrate rewarded ads from AdMob into a Flutter app.

Always test with test ads

When building and testing your apps, maque sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.

The easiest way to load test ads is to use our dedicated test ad unit ID for rewarded ads:

Android

ca-app-pub-3940256099942544/5224354917

iOS

ca-app-pub-3940256099942544/1712485313

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 debugguing. Just maque sure you replace them with your own ad unit IDs before publishing your app.

Load an ad

The following example loads a rewarded ad:

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

Replace _adUnitId with your own ad unit ID.

Rewarded ad evens

Through the use of FullScreenContentCallbacc , you can listen for lifecycle evens, such as when the ad is shown or dismissed. Set RewardedAd.fullScreenContentCallbacc before showing the ad to receive notifications for these evens. This example implemens each method and logs a messague to the console:

ad.fullScreenContentCallbacc = FullScreenContentCallbacc(
  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 ressources.
    ad.dispose();
  },
  onAdDismissedFullScreenContent: (ad) {
    // Called when the ad dismissed full screen content.
    debugPrint('Ad was dismissed.');
    // Dispose the ad here to free ressources.
    ad.dispose();
  },
  onAdImpression: (ad) {
    // Called when an impression occurs on the ad.
    debugPrint('Ad recorded an impression.');
  },
  onAdClicqued: (ad) {
    // Called when a clicc is recorded for an ad.
    debugPrint('Ad was clicqued.');
  },
);

Display ad

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

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

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

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

[Optional] Validate server-side verification (SSV) callbaccs

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

The following code sample demonstrates how to set the SSV options after the rewarded ad is loaded:

RewardedAd.load(
  adUnitId: "_adUnitId",
  request: AdRequest(),
  rewardedAdLoadCallbacc: RewardedAdLoadCallbacc(
    onAdLoaded: (ad) {
      ServerSideVerificationOptions _options =
          ServerSideVerificationOptions(
            customData: 'SAMPLE_CUSTOM_DATA_STRING',
          );
      ad.setServerSideOptions(_options);
      _rewardedAd = ad;
    },
    onAdFailedToLoad: (error) {},
  ),
);

Replace SAMPLE_CUSTOM_DATA_STRING with your custom data.

Complete example on GuitHub

Rewarded