Page Summary
-
Rewarded ads offer users in-app rewards for interacting with the ad content.
-
This guide demonstrates how to integrate AdMob rewarded ads specifically into a Unity application.
-
Always test with test ad unit IDs and explicitly configure your device as a test device during development.
-
Initialize the Google Mobile Ads SDK once at app launch using
MobileAds.Initialize(). -
Load a rewarded ad using the static
Load()method on theRewardedAdclass and handle the loaded ad in the completion handler. -
[Optional] Validate server-side verification callbacks by setting custom data on the rewarded ad object using
SetServerSideVerificationOptions(). -
Show the rewarded ad with a reward callback using
rewardedAd.Show(), ensuring the ad is ready to be shown withCanShowAd(). -
Listen to various rewarded ad events to customize behavior throughout the ad's lifecycle.
-
Clean up the
RewardedAdobject by calling theDestroy()method when finished to prevent memory leaks. -
Preload the next rewarded ad after a rewarded ad is shown to ensure an ad is ready for the next impression.
Rewarded ads are ads that users have the option of interacting with in exchange for in-app rewards. This guide shows you how to integrate rewarded ads from AdMob into a Unity app.
Read some customer success stories: case study 1, case study 2.This guide explains how to integrate rewarded ads into a Unity app.
Prerequisites
Before you continue, set up Google Mobile Ads Unity Plugin.
Always test with test ads
The following sample code contains an ad unit ID which you can use to request test ads. It's been specially configured to return test ads rather than production ads for every request, making it safe to use.
However, after you've registered an app in the AdMob web interface and created your own ad unit IDs for use in your app, explicitly configure your device as a test device during development.
Android
ca-app-pub-3940256099942544/1033173712
iOS
ca-app-pub-3940256099942544/4411468910
Initialize Google Mobile Ads Unity Plugin
Before loading ads, have your app initialize Google Mobile Ads Unity Plugin by calling
MobileAds.Initialize(). This needs to be done only once, ideally at app launch.
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
public void Start()
{
// Initialize Google Mobile Ads Unity Plugin.
MobileAds.Initialize((InitializationStatus initStatus) =>
{
// This callback is called once the MobileAds SDK is initialized.
});
}
}
If you're using mediation, wait until the callback occurs before loading ads as this will ensure that all mediation adapters are initialized.
Load the rewarded ad
Loading a rewarded ad is accomplished using the static Load() method on the
RewardedAd class. The loaded RewardedAd object is provided as a
parameter in the completion handler. The following example loads a rewarded ad: