Rewarded interstitial (beta)

Select platform: Android iOS Unity Flutter

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.

Prerequisites

  • Google Mobile Ads SDK 19.2.0 or higher.

Implementation

The primary steps to integrate rewarded interstitial ads are as follows:

  • Load an ad
  • Register for full screen event callbacks
  • Handle the reward callback
  • Display the ad
  • [Optional] Validate SSV callbacks

Load an ad

Loading an ad is accomplished using the static load() method on the RewardedInterstitialAd class. The load method requires a Context, your ad unit ID, an AdRequest object, and a RewardedInterstitialAdLoadCallback to be notified when ad loading succeeds or fails. The loaded RewardedInterstitialAd object is provided as a parameter in the onRewardedInterstitialAdLoaded() callback.

The following example shows how to load a RewardedInterstitialAd in your MainActivity .

Java

  RewardedInterstitialAd 
 . 
 load 
 ( 
  
 MainActivity 
 . 
 this 
 , 
  
 " AD_UNIT_ID 
" 
 , 
  
 new 
  
 AdRequest 
 . 
 Builder 
 (). 
 build 
 (), 
  
 new 
  
 RewardedInterstitialAdLoadCallback 
 () 
  
 { 
  
 @Override 
  
 public 
  
 void 
  
 onAdLoaded 
 ( 
 RewardedInterstitialAd 
  
 ad 
 ) 
  
 { 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "Ad was loaded." 
 ); 
  
 rewardedInterstitialAd 
  
 = 
  
 ad 
 ; 
  
 } 
  
 @Override 
  
 public 
  
 void 
  
 onAdFailedToLoad 
 ( 
 LoadAdError 
  
 loadAdError 
 ) 
  
 { 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "onAdFailedToLoad: " 
  
 + 
  
 loadAdError 
 . 
 getMessage 
 ()); 
  
 rewardedInterstitialAd 
  
 = 
  
 null 
 ; 
  
 } 
  
 }); 
  
 

Kotlin

  RewardedInterstitialAd 
 . 
 load 
 ( 
  
 this 
 , 
  
 " AD_UNIT_ID 
" 
 , 
  
 AdRequest 
 . 
 Builder 
 (). 
 build 
 (), 
  
 object 
  
 : 
  
 RewardedInterstitialAdLoadCallback 
 () 
  
 { 
  
 override 
  
 fun 
  
 onAdLoaded 
 ( 
 rewardedAd 
 : 
  
 RewardedInterstitialAd 
 ) 
  
 { 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "Ad was loaded." 
 ) 
  
 rewardedInterstitialAd 
  
 = 
  
 rewardedAd 
  
 } 
  
 override 
  
 fun 
  
 onAdFailedToLoad 
 ( 
 adError 
 : 
  
 LoadAdError 
 ) 
  
 { 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "onAdFailedToLoad: 
 ${ 
 adError 
 . 
 message 
 } 
 " 
 ) 
  
 rewardedInterstitialAd 
  
 = 
  
 null 
  
 } 
  
 }, 
 ) 
  
 

Replace AD_UNIT_ID with your ad unit ID.

Register for callbacks

In order to receive notifications for presentation events, you must pass a FullScreenContentCallback object to the setter on your ad. The FullScreenContentCallback object handles callbacks for when the ad presents successfully or unsuccessfully, and when it is dismissed. The following code shows how to set an anonymous FullScreenContentCallback object within your RewardedInterstitialAdLoadCallback :

Java

  rewardedInterstitialAd 
 . 
 setFullScreenContentCallback 
 ( 
  
 new 
  
 FullScreenContentCallback 
 () 
  
 { 
  
 @Override 
  
 public 
  
 void 
  
 onAdDismissedFullScreenContent 
 () 
  
 { 
  
 // Called when fullscreen content is dismissed. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "The ad was dismissed." 
 ); 
  
 // Make sure to set your reference to null so you don't 
  
 // show it a second time. 
  
 rewardedInterstitialAd 
  
 = 
  
 null 
 ; 
  
 if 
  
 ( 
 googleMobileAdsConsentManager 
 . 
 canRequestAds 
 ()) 
  
 { 
  
 loadRewardedInterstitialAd 
 (); 
  
 } 
  
 } 
  
 @Override 
  
 public 
  
 void 
  
 onAdFailedToShowFullScreenContent 
 ( 
 AdError 
  
 adError 
 ) 
  
 { 
  
 // Called when fullscreen content failed to show. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "The ad failed to show." 
 ); 
  
 // Make sure to set your reference to null so you don't 
  
 // show it a second time. 
  
 rewardedInterstitialAd 
  
 = 
  
 null 
 ; 
  
 } 
  
 @Override 
  
 public 
  
 void 
  
 onAdShowedFullScreenContent 
 () 
  
 { 
  
 // Called when fullscreen content is shown. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "The ad was shown." 
 ); 
  
 } 
  
 @Override 
  
 public 
  
 void 
  
 onAdImpression 
 () 
  
 { 
  
 // Called when an impression is recorded for an ad. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "The ad recorded an impression." 
 ); 
  
 } 
  
 @Override 
  
 public 
  
 void 
  
 onAdClicked 
 () 
  
 { 
  
 // Called when ad is clicked. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "The ad was clicked." 
 ); 
  
 } 
  
 }); 
  
 

Kotlin

  rewardedInterstitialAd 
 ?. 
 fullScreenContentCallback 
  
 = 
  
 object 
  
 : 
  
 FullScreenContentCallback 
 () 
  
 { 
  
 override 
  
 fun 
  
 onAdDismissedFullScreenContent 
 () 
  
 { 
  
 // Called when fullscreen content is dismissed. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "Ad was dismissed." 
 ) 
  
 // Don't forget to set the ad reference to null so you 
  
 // don't show the ad a second time. 
  
 rewardedInterstitialAd 
  
 = 
  
 null 
  
 } 
  
 override 
  
 fun 
  
 onAdFailedToShowFullScreenContent 
 ( 
 adError 
 : 
  
 AdError 
 ) 
  
 { 
  
 // Called when fullscreen content failed to show. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "Ad failed to show." 
 ) 
  
 // Don't forget to set the ad reference to null so you 
  
 // don't show the ad a second time. 
  
 rewardedInterstitialAd 
  
 = 
  
 null 
  
 } 
  
 override 
  
 fun 
  
 onAdShowedFullScreenContent 
 () 
  
 { 
  
 // Called when fullscreen content is shown. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "Ad showed fullscreen content." 
 ) 
  
 } 
  
 override 
  
 fun 
  
 onAdImpression 
 () 
  
 { 
  
 // Called when an impression is recorded for an ad. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "Ad recorded an impression." 
 ) 
  
 } 
  
 override 
  
 fun 
  
 onAdClicked 
 () 
  
 { 
  
 // Called when an ad is clicked. 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "Ad was clicked." 
 ) 
  
 } 
  
 } 
  
 

Show the ad

When you show a rewarded interstitial ad, you use an OnUserEarnedRewardListener object to handle reward events.

Java

  rewardedInterstitialAd 
 . 
 show 
 ( 
  
 MainActivity 
 . 
 this 
 , 
  
 new 
  
 OnUserEarnedRewardListener 
 () 
  
 { 
  
 @Override 
  
 public 
  
 void 
  
 onUserEarnedReward 
 ( 
 @NonNull 
  
 RewardItem 
  
 rewardItem 
 ) 
  
 { 
  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "The user earned the reward." 
 ); 
  
 // Handle the reward. 
  
 int 
  
 rewardAmount 
  
 = 
  
 rewardItem 
 . 
 getAmount 
 (); 
  
 String 
  
 rewardType 
  
 = 
  
 rewardItem 
 . 
 getType 
 (); 
  
 } 
  
 }); 
  
 

Kotlin

  rewardedInterstitialAd 
 ?. 
 show 
 ( 
 this 
 ) 
  
 { 
  
 rewardItem 
  
 - 
>  
 Log 
 . 
 d 
 ( 
 TAG 
 , 
  
 "User earned the reward." 
 ) 
  
 // Handle the reward. 
  
 val 
  
 rewardAmount 
  
 = 
  
 rewardItem 
 . 
 amount 
  
 val 
  
 rewardType 
  
 = 
  
 rewardItem 
 . 
 type 
 } 
  
 

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

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.

The following code sample demonstrates how to set custom data on a rewarded interstitial ad object before requesting an ad.

Java

  RewardedInterstitialAd 
 . 
 load 
 ( 
  
 context 
 , 
  
 AD_UNIT_ID 
 , 
  
 new 
  
 AdRequest 
 . 
 Builder 
 (). 
 build 
 (), 
  
 new 
  
 RewardedInterstitialAdLoadCallback 
 () 
  
 { 
  
 @Override 
  
 public 
  
 void 
  
 onAdLoaded 
 ( 
 RewardedInterstitialAd 
  
 ad 
 ) 
  
 { 
  
 rewardedInterstitialAd 
  
 = 
  
 ad 
 ; 
   
 ServerSideVerificationOptions 
  
 options 
  
 = 
   
 new 
  
 ServerSideVerificationOptions 
 . 
 Builder 
 () 
   
 . 
 setCustomData 
 ( 
 " SAMPLE_CUSTOM_DATA_STRING 
" 
 ) 
   
 . 
 build 
 (); 
   
 rewardedInterstitialAd 
 . 
 setServerSideVerificationOptions 
 ( 
 options 
 ); 
  
 } 
  
 }); 
  
 

Kotlin

  RewardedInterstitialAd 
 . 
 load 
 ( 
  
 context 
 , 
  
 AD_UNIT_ID 
 , 
  
 AdRequest 
 . 
 Builder 
 (). 
 build 
 (), 
  
 object 
  
 : 
  
 RewardedInterstitialAdLoadCallback 
 () 
  
 { 
  
 override 
  
 fun 
  
 onAdLoaded 
 ( 
 ad 
 : 
  
 RewardedInterstitialAd 
 ) 
  
 { 
  
 rewardedInterstitialAd 
  
 = 
  
 ad 
   
 val 
  
 options 
  
 = 
   
 ServerSideVerificationOptions 
 . 
 Builder 
 (). 
 setCustomData 
 ( 
 " SAMPLE_CUSTOM_DATA_STRING 
" 
 ). 
 build 
 () 
   
 rewardedInterstitialAd 
 ?. 
 setServerSideVerificationOptions 
 ( 
 options 
 ) 
   
 } 
   
 }, 
 ) 
  
 

Replace SAMPLE_CUSTOM_DATA_STRING with your custom data.

If you want to set the custom reward string, you must do so before showing the ad.

Examples on GitHub

  • Rewarded Interstitial ads example: Java | Kotlin

Next steps

Explore the following topics:

Create a Mobile Website
View Site in Mobile | Classic
Share by: