Select platform: [Android](https://developers.google.com/admob/android/next-gen/rewarded "View this page for the Android platform documentation.") [iOS](https://developers.google.com/admob/ios/rewarded "View this page for the iOS platform documentation.") [Unity](https://developers.google.com/admob/unity/rewarded "View this page for the Unity platform documentation.") [Flutter](https://developers.google.com/admob/flutter/rewarded "View this page for the Flutter platform documentation.") [Android (Legacy)](https://developers.google.com/admob/android/rewarded "View this page for the Android (Legacy) platform documentation.")

<br />

[Video](https://www.youtube.com/watch?v=UOptam261Ts)

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](https://admob.google.com/home/resources/kongregate-uses-admob-to-boost-revenue-average-30-dollar-cpm/), [case study 2](https://admob.google.com/home/resources/four-thirty-three-uses-admob-to-boost-mobile-game-revenue-15-percent/).

This guide explains how to integrate rewarded ads into a Unity app.

## Prerequisites

Before you continue, [set up Google Mobile Ads Unity Plugin](https://developers.google.com/admob/unity/quick-start).

## 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](https://developers.google.com/admob/unity/test-ads#enable_test_devices) 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:

    // Create our request used to load the ad.
    var adRequest = new AdRequest();

    // Send the request to load the ad.
    RewardedAd.Load("AD_UNIT_ID", adRequest, (RewardedAd ad, LoadAdError error) =>
    {
        if (error != null)
        {
            // The ad failed to load.
            return;
        }
        // The ad loaded successfully.
    });

Replace <var class="readonly" translate="no">AD_UNIT_ID</var> with your ad unit ID.

> [!WARNING]
> **Warning:** Attempting to load a new ad from the ad request completion block when an ad failed to load is strongly discouraged. If you must load an ad from the ad request completion block, limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity.


> [!TIP]
> **Tip:** You can use ad load calls to build up a cache of preloaded ads before you intend to show them, so that ads can be shown with zero latency when needed. Because ads expire after an hour, you should clear this cache and reload with new ads every hour.

<br />

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

Apps that require extra data in [server-side verification](https://developers.google.com/admob/unity/ssv)
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 ad is loaded.

    // Create and pass the SSV options to the rewarded ad.
    var options = new ServerSideVerificationOptions
    {
        CustomData = ""SAMPLE_CUSTOM_DATA_STRING""
    };

    rewardedAd.SetServerSideVerificationOptions(options);

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

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

> [!IMPORTANT]
> **Key Point:** The custom reward string is [percent
> escaped](https://en.wikipedia.org/wiki/Percent-encoding) and might require decoding when parsed from the SSV callback.

## Show the rewarded ad with reward callback

When presenting your ad, you must provide a callback to handle the reward for
the user. Ads can only be shown once per load. Use the `CanShowAd()` method to
verify that the ad is ready to be shown.

The following code presents the best method for displaying a rewarded ad.

    if (rewardedAd != null && rewardedAd.CanShowAd())
    {
        rewardedAd.Show((Reward reward) =>
        {
            // The ad was showen and the user earned a reward.
        });
    }

## Listen to rewarded ad events

To further customize the behavior of your ad, you can hook into a number of
events in the ad's lifecycle. The following code listens for ad events:

    rewardedAd.OnAdPaid += (AdValue adValue) =>
    {
        // Raised when the ad is estimated to have earned money.
    };
    rewardedAd.OnAdImpressionRecorded += () =>
    {
        // Raised when an impression is recorded for an ad.
    };
    rewardedAd.OnAdClicked += () =>
    {
        // Raised when a click is recorded for an ad.
    };
    rewardedAd.OnAdFullScreenContentOpened += () =>
    {
        // Raised when the ad opened full screen content.
    };
    rewardedAd.OnAdFullScreenContentClosed += () =>
    {
        // Raised when the ad closed full screen content.
    };
    rewardedAd.OnAdFullScreenContentFailed += (AdError error) =>
    {
        // Raised when the ad failed to open full screen content.
    };

## Clean up the rewarded ad

When you are finished with a `RewardedAd`, make sure to call the `Destroy()`
method before dropping your reference to it:

    if (rewardedAd != null)
    {
        rewardedAd.Destroy();
    }

This notifies the plugin that the object is no longer used and the memory it
occupies can be reclaimed. Failure to call this method results in memory leaks.

## Preload the next rewarded ad

`RewardedAd` is a one-time-use object. This means once a rewarded ad is shown,
the object can't be used again. To request another rewarded ad,
you'll need to create a new `RewardedAd` object.

To prepare a rewarded ad for the next impression opportunity, preload the
rewarded ad once the `OnAdFullScreenContentClosed` or
`OnAdFullScreenContentFailed` ad event is raised.

    rewardedAd.OnAdFullScreenContentClosed += () =>
    {
        // Reload the ad so that we can show another as soon as possible.
        var adRequest = new AdRequest();
        RewardedAd.Load("AD_UNIT_ID", adRequest, (RewardedAd ad, LoadAdError error) =>
        {
            // Handle ad loading here.
        });
    };

## Additional resources

- [HelloWorld example](https://github.com/googleads/googleads-mobile-unity/tree/main/samples/HelloWorld): A minimal implementation of all ad formats.