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 Ad Manager into a Flutter app.
Prerequisites
- Flutter plugin 1.1.0 or higher.
- Complete Get Started. Your Flutter app should already have the 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:
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'); }, )); } }
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:
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'); }, )); } }
Display ad
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 ad, RewardItem rewardItem) { // Reward the user for watching an ad. });
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.
That's it! Your app is now ready to display rewarded interstitial ads.