<br />

Rewarded interstitial is a type of incentivized ad format that lets you offer
[rewards](https://support.google.com/admob/answer/7313578) 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 Ad Manager
into a Flutter app.

## Prerequisites

Before you continue, do the following:

- Install Flutter plugin 1.1.0 or higher.
- [Set up Google Mobile Ads Flutter Plugin](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/quick-start.md.txt). Your Flutter app must have Google Mobile Ads Flutter Plugin imported.

## Always test with test ads

When building and testing your apps, make 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 interstitial ads:

- `/21775744923/example/rewarded-interstitial`

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.

## Load an ad

The following example loads a rewarded interstitial ad:

```dart
RewardedInterstitialAd.load(
  adUnitId: "_adUnitId",
  request: const AdManagerAdRequest(),
  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');
    },
  ),
);
```

Replace <var translate="no">_adUnitId</var> with your own ad unit ID.

### Rewarded interstitial ad events

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:

```dart
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.');
  },
);
```

## Display ad

> [!IMPORTANT]
> **Key Point:** Before displaying a rewarded interstitial ad to users, you must present the user with an intro screen that provides clear reward messaging and an option to skip the ad before it starts. [Learn
> more](https://support.google.com/admanager/answer/7386053).

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.

```dart
_rewardedInterstitialAd?.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 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.

## \[Optional\] Validate server-side verification (SSV) callbacks

Apps that require extra data in [server-side verification](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/ssv.md.txt)
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.

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

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

Replace <var translate="no">SAMPLE_CUSTOM_DATA_STRING</var> with your custom data.