---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ads.yandex.com/helpcenter/en/dev/unity/rewarded.md
  - https://ads.yandex.com/helpcenter/pt/dev/unity/rewarded.md
  - https://ads.yandex.com/helpcenter/ru/dev/unity/rewarded.md
  - https://ads.yandex.com/helpcenter/zh/dev/unity/rewarded.md
  - href: en/dev/unity/rewarded.md
    type: text/markdown
    title: Markdown version
  - href: llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://ads.yandex.com/helpcenter/en/llms.txt

# Rewarded ads

<!-- source: en/dev/_includes/rewarded.md -->
Rewarded ads are a popular fullscreen ad format where users receive incentives for viewing ads.
<!-- endsource: en/dev/_includes/rewarded.md -->

<!-- source: en/dev/_includes/rewarded.md -->
Ad impressions are opt-in: for example, users can initiate them to get game bonuses or extra lives.
<!-- endsource: en/dev/_includes/rewarded.md -->

<!-- source: en/dev/_includes/rewarded.md -->
Strong user motivation makes this ad format the most popular and profitable adoption in free apps.
<!-- endsource: en/dev/_includes/rewarded.md -->

{% cut "Appearance" %}

{% list tabs %}

- Text and image ads

  <iframe width="200" height="405.5" allow="autoplay" src="https://runtime.strm.yandex.ru/player/video/vplv6tshzb3euhokoa5q?autoplay=1&mute=0&loop=1&loop=1" frameborder="0" allowfullscreen></iframe>

- Video ads

  <iframe width="200" height="405.5" allow="autoplay" src="https://runtime.strm.yandex.ru/player/video/vplvv2aom7x2nte5gckn?autoplay=1&mute=0&loop=1&loop=1" frameborder="0" allowfullscreen></iframe>

{% endlist %}

{% endcut %}

This guide will show how to integrate rewarded ads into Unity apps. In addition to code examples and instructions, it contains format-specific recommendations and links to additional resources.

## Prerequisite {#pre}

<!-- source: en/dev/_includes/pre-unity.md -->
1. Follow the process in [Quick start](https://ads.yandex.com/helpcenter/en/dev/unity/quick-start.md) for integrating the Yandex Mobile Ads Unity Plugin.
2. Make sure you're running the latest [Yandex Mobile Ads Unity Plugin](https://ads.yandex.com/helpcenter/en/dev/platforms.md) version. If you're using mediation, make sure you're also running the latest version of the [unified build](https://ads.yandex.com/helpcenter/en/dev/platforms.md).
<!-- endsource: en/dev/_includes/pre-unity.md -->

## Implementation {#implement}

Key steps for integrating rewarded ads:

1. Create a `RewardedAdLoader` ad loader.
2. Load an ad with the `RewardedAdLoader.LoadAd(AdRequest)` method using `async/await` or callbacks.
3. Register listeners for events where users interact with your ad.
4. Show the ad by calling the `RewardedAd.Show()` method.
5. Release the resources.

## Features of rewarded ad integration {#features}

1. If loading failed, don't try to load a new ad again. If there's no other option, limit the number of ad load retries. That will help avoid constant unsuccessful requests and connection issues when limitations arise.

2. We recommend using a single instance of `RewardedAdLoader` for all ad loads to improve performance.

## Step-by-step guide

1. Create a `RewardedAdLoader` object in the C# script attached to `GameObject`.

   ```c#
   using UnityEngine;
   using YandexMobileAds;
   using YandexMobileAds.Base;

   public class YandexMobileAdsRewardedAdDemoScript : MonoBehaviour
   {
       private RewardedAdLoader rewardedAdLoader;
       private RewardedAd rewardedAd;

       private void SetupLoader()
       {
           rewardedAdLoader = new RewardedAdLoader();
           // ...
       }
   }
   ```

2. Load an ad with the `LoadAd` method.

   {% list tabs %}

   - async/await

     ```c#
     private async void RequestRewardedAd()
     {
         string adUnitId = "demo-rewarded-yandex"; // replace with "R-M-XXXXXX-Y"
         try
         {
             rewardedAd = await rewardedAdLoader.LoadAd(new AdRequest(adUnitId));
         }
         catch (AdLoadingException e)
         {
             // Ad failed to load with {e.Message}
             // Attempting to load a new ad from catch block is strongly discouraged.
         }
     }
     ```

   - Callbacks

     ```c#
     private void RequestRewardedAd()
     {
         string adUnitId = "demo-rewarded-yandex"; // replace with "R-M-XXXXXX-Y"
         AdRequest adRequest = new AdRequest(adUnitId);
         rewardedAdLoader.LoadAd(
             adRequest: adRequest,
             onLoaded: rewardedAd => {
                 // Rewarded ad was loaded successfully. Now you can handle it.
                 this.rewardedAd = rewardedAd;
             },
             onFailed: args => {
                 // Ad failed to load with {args.Message}
                 // Attempting to load new ad from the onFailed callback is strongly discouraged.
             });
     }
     ```

   {% endlist %}

   `adUnitId` is a unique identifier that is issued in the Yandex Advertising Network interface and looks like this: R-M-XXXXXX-Y.

   {% note tip %}

   For testing purposes, you can use the demo unit ID: "demo-rewarded-yandex". Before publishing your ad, make sure to replace the demo unit ID with a real ad unit ID.

   You can expand the ad request parameters through the `AdTargeting` class by passing user interests, contextual app data, location details, or other data. Delivering additional contextual data in the request can significantly improve your ad quality. Read more in the [Ad Targeting](https://ads.yandex.com/helpcenter/en/dev/unity/target.md) section.

   {% endnote %}

3. Register listeners for events where users interact with your ad.

   ```c#
   using System;

   // ...
   rewardedAd.OnAdClicked += HandleAdClicked;
   rewardedAd.OnAdShown += HandleAdShown;
   rewardedAd.OnAdFailedToShow += HandleAdFailedToShow;
   rewardedAd.OnAdImpression += HandleImpression;
   rewardedAd.OnAdDismissed += HandleAdDismissed;
   rewardedAd.OnRewarded += HandleRewarded;
   // ...

   public void HandleAdClicked(object sender, EventArgs args)
   {
       // Called when a click is recorded for rewarded ad.
   }

   public void HandleAdShown(object sender, EventArgs args)
   {
       // Called when an ad is shown.
   }

   public void HandleAdFailedToShow(object sender, AdFailureEventArgs args)
   {
       // Called when an ad failed to show.
   }

   public void HandleAdDismissed(object sender, EventArgs args)
   {
       // Called when an ad is dismissed.
   }

   public void HandleImpression(object sender, ImpressionData impressionData)
   {
       // Called when an impression is recorded for an ad.
   }

   public void HandleRewarded(object sender, Reward args)
   {
       // Called when the user can be rewarded with {args.type} and {args.amount}.
   }
   ```

4. Show the ad by calling `Show()` on the `RewardedAd` object.

   ```c#
   private void ShowRewardedAd()
   {
       if (rewardedAd != null)
       {
           rewardedAd.Show();
       }
   }
   ```

5. Call `Destroy()` on ads that are shown and clear links that are no longer used on the current screen.

   That releases the resources and prevents memory leaks.

   ```c#
   public void DestroyRewardedAd()
   {
       if (rewardedAd != null)
       {
           rewardedAd.Destroy();
           rewardedAd = null;
       }
   }
   ```

## Testing the rewarded ad integration {#test}

{% list tabs %}

- Android

   <!-- source: en/dev/_includes/test-android-rewarded.md -->
   ### Using demo ad units for ad testing {#demo-blocks}

   Use test ads to check your rewarded ad integration and the app itself. To make sure that test ads are returned for each ad request, you can use a special demo ad placement ID.

   Demo adUnitId: `demo-rewarded-yandex`.

   {% note warning %}

   Before publishing your app in the store, make sure to replace the demo placement ID with the real ID you obtained in the Yandex Advertising Network interface.

   {% endnote %}

   For the list of all available demo ad placement IDs, see [Demo ad units for testing](https://ads.yandex.com/helpcenter/en/dev/android/demo-blocks.md).

   ### Testing ad integration {#test-int}

   You can check if your rewarded ads are integrated correctly using the SDK's built-in analyzer. A detailed report with the test results will appear in the log.

   To view the report, search for the keyword “YandexAds” in [Logcat](https://developer.android.com/studio/command-line/logcat), a tool for debugging Android apps.
   ```bash
   adb logcat -v brief '*:S YandexAds'
   ```

   If the integration is successful, the following message is returned:
   ```bash
   adb logcat -v brief '*:S YandexAds'
   mobileads$ adb logcat -v brief '*:S YandexAds'
   I/YandexAds(13719): [Integration] Ad type rewarded was integrated successfully
   ```

   If there are any rewarded ad integration issues, you'll get a detailed issue report and troubleshooting recommendations.
   <!-- endsource: en/dev/_includes/test-android-rewarded.md -->

- iOS

   ### Using demo ad units for ad testing

   <!-- source: en/dev/_includes/test-ios-rewarded.md -->
   We recommend using test ads to test your ad integration and your app itself.

   To guarantee that test ads are returned for every ad request, we created a special demo ad placement ID. Use it to check your ad integration.

   Demo adUnitId: `demo-rewarded-yandex`.

   {% note warning %}

   Before publishing your app to the store, make sure you replace the demo ad unit ID with a real one obtained from the Yandex Advertising Network interface.

   {% endnote %}

   You can find the list of available demo ad placement IDs in the [Demo ad units for testing](https://ads.yandex.com/helpcenter/en/dev/ios/demo-blocks.md) section.
   <!-- endsource: en/dev/_includes/test-ios-rewarded.md -->

   ### Testing ad integration

   <!-- source: en/dev/_includes/test-integration-ios.md -->
   You can test your ad integration using the native Console tool.

   To view detailed logs, call the `YandexAds` class's `enableLogging` method.

   ```swift
   YandexAds.enableLogging()
   ```

   To view SDK logs, go to the Console tool and set `Subsystem = com.mobile.ads.ads.sdk`. You can also filter logs by category and error level.

   If you're having problems integrating ads, you'll get a detailed report on the issues and recommendations for how to fix them.

   <img src= "https://yastatic.net/s3/doc-binary/src/dev/mobile-ads/common/integration-ios-2.png">
   <!-- endsource: en/dev/_includes/test-integration-ios.md -->

{% endlist %}

## Tips

### Ad preloading

<!-- source: en/dev/_includes/preload.md -->
Loading an ad may take several seconds, depending on the number of ad networks connected in mobile mediation and the user's internet speed. We recommend preloading ads before displaying them.
<!-- endsource: en/dev/_includes/preload.md -->

You can call ad loading in the `Awake` method for `gameObject`. Make sure to preserve the object between scenes using the `DontDestroyOnLoad()` call. That ensures the ad that's loaded is not deleted with `gameObject` on scene change.

```c#
private void Awake()
{
    SetupLoader();
    RequestRewardedAd();
    DontDestroyOnLoad(gameObject);
}
```

Along with that, you can bind loading of the next ad to the callback functions run when ad show completes or fails. For example, like this:

```c#
public void HandleAdFailedToShow(object sender, EventArgs args)
{
    // Called when an ad failed to show.

    // Clear resources after an ad dismissed.
    DestroyRewardedAd();

    // Now you can preload the next rewarded ad.
    RequestRewardedAd();
}

public void HandleAdDismissed(object sender, EventArgs args)
{
    // Called when an ad is dismissed.

    // Clear resources after an ad dismissed.
    DestroyRewardedAd();

    // Now you can preload the next rewarded ad.
    RequestRewardedAd();
}
```

<!-- source: en/dev/_includes/cash-ads.md -->
If you cache ads on too many screens that are unlikely to be shown, your ad effectiveness could drop. For example, if users complete 2-3 game levels per session, you shouldn't cache ads for 6-7 screens. Your ad viewability could decrease otherwise, and the advertising system might deprioritize your app.

To make sure you're finding a good balance for your app, track the "Share of impressions" or "Share of visible impressions" metric in the Yandex Advertising Network interface. If it's under 20%, you should probably revise your caching algorithm. The higher the percentage of impressions, the better.
<!-- endsource: en/dev/_includes/cash-ads.md -->

### Full code example

{% list tabs %}

- async/await

  ```c#
  using System;
  using UnityEngine;
  using UnityEngine.UI;
  using YandexMobileAds;
  using YandexMobileAds.Base;

  public class YandexMobileAdsRewardedAdDemoScript : MonoBehaviour
  {
      private RewardedAdLoader rewardedAdLoader;
      private RewardedAd rewardedAd;
      [SerializeField] private Button button;

      private void Awake()
      {
          SetupLoader();
          RequestRewardedAd();
          DontDestroyOnLoad(gameObject);
          button = this.GetComponent<Button>();
          button.onClick.AddListener(ShowRewardedAd);
      }

      private void SetupLoader()
      {
          rewardedAdLoader = new RewardedAdLoader();
      }

      private async void RequestRewardedAd()
      {
          string adUnitId = "demo-rewarded-yandex"; // replace with "R-M-XXXXXX-Y"
          try
          {
              rewardedAd = await rewardedAdLoader.LoadAd(new AdRequest(adUnitId));

              // Add events handlers for ad actions
              rewardedAd.OnAdClicked += HandleAdClicked;
              rewardedAd.OnAdShown += HandleAdShown;
              rewardedAd.OnAdFailedToShow += HandleAdFailedToShow;
              rewardedAd.OnAdImpression += HandleImpression;
              rewardedAd.OnAdDismissed += HandleAdDismissed;
              rewardedAd.OnRewarded += HandleRewarded;
          }
          catch (AdLoadingException e)
          {
              // Ad failed to load with {e.Message}
              // Attempting to load a new ad from catch block is strongly discouraged.
          }
      }

      private void ShowRewardedAd()
      {
          if (rewardedAd != null)
          {
              rewardedAd.Show();
          }
      }

      public void HandleAdDismissed(object sender, EventArgs args)
      {
          // Called when an ad is dismissed.

          // Clear resources after an ad dismissed.
          DestroyRewardedAd();

          // Now you can preload the next rewarded ad.
          RequestRewardedAd();
      }

      public void HandleAdFailedToShow(object sender, AdFailureEventArgs args)
      {
          // Called when rewarded ad failed to show.

          // Clear resources after an ad dismissed.
          DestroyRewardedAd();

          // Now you can preload the next rewarded ad.
          RequestRewardedAd();
      }

      public void HandleAdClicked(object sender, EventArgs args)
      {
          // Called when a click is recorded for an ad.
      }

      public void HandleAdShown(object sender, EventArgs args)
      {
          // Called when an ad is shown.
      }

      public void HandleImpression(object sender, ImpressionData impressionData)
      {
          // Called when an impression is recorded for an ad.
      }

      public void HandleRewarded(object sender, Reward args)
      {
          // Called when the user can be rewarded with {args.type} and {args.amount}.
      }

      public void DestroyRewardedAd()
      {
          if (rewardedAd != null)
          {
              rewardedAd.Destroy();
              rewardedAd = null;
          }
      }
  }
  ```

- Callbacks

  ```c#
  using System;
  using UnityEngine;
  using UnityEngine.UI;
  using YandexMobileAds;
  using YandexMobileAds.Base;

  public class YandexMobileAdsRewardedAdDemoScript : MonoBehaviour
  {
      private RewardedAdLoader rewardedAdLoader;
      private RewardedAd rewardedAd;
      [SerializeField] private Button button;

      private void Awake()
      {
          SetupLoader();
          RequestRewardedAd();
          DontDestroyOnLoad(gameObject);
          button = this.GetComponent<Button>();
          button.onClick.AddListener(ShowRewardedAd);
      }

      private void SetupLoader()
      {
          rewardedAdLoader = new RewardedAdLoader();
      }

      private void RequestRewardedAd()
      {
          string adUnitId = "demo-rewarded-yandex"; // replace with "R-M-XXXXXX-Y"
          AdRequest adRequest = new AdRequest(adUnitId);
          rewardedAdLoader.LoadAd(
              adRequest: adRequest,
              onLoaded: HandleAdLoaded,
              onFailed: HandleAdFailedToLoad);
      }

      private void ShowRewardedAd()
      {
          if (rewardedAd != null)
          {
              rewardedAd.Show();
          }
      }

      public void HandleAdLoaded(RewardedAd rewardedAd)
      {
          // The ad was loaded successfully. Now you can handle it.
          this.rewardedAd = rewardedAd;

          // Add events handlers for ad actions
          this.rewardedAd.OnAdClicked += HandleAdClicked;
          this.rewardedAd.OnAdShown += HandleAdShown;
          this.rewardedAd.OnAdFailedToShow += HandleAdFailedToShow;
          this.rewardedAd.OnAdImpression += HandleImpression;
          this.rewardedAd.OnAdDismissed += HandleAdDismissed;
          this.rewardedAd.OnRewarded += HandleRewarded;
      }

      public void HandleAdFailedToLoad(AdFailedToLoadEventArgs args)
      {
          // Ad failed to load with {args.Message}
          // Attempting to load a new ad from the onFailed callback is strongly discouraged.
      }

      public void HandleAdDismissed(object sender, EventArgs args)
      {
          // Called when an ad is dismissed.

          // Clear resources after an ad dismissed.
          DestroyRewardedAd();

          // Now you can preload the next rewarded ad.
          RequestRewardedAd();
      }

      public void HandleAdFailedToShow(object sender, AdFailureEventArgs args)
      {
          // Called when rewarded ad failed to show.

          // Clear resources after an ad dismissed.
          DestroyRewardedAd();

          // Now you can preload the next rewarded ad.
          RequestRewardedAd();
      }

      public void HandleAdClicked(object sender, EventArgs args)
      {
          // Called when a click is recorded for an ad.
      }

      public void HandleAdShown(object sender, EventArgs args)
      {
          // Called when an ad is shown.
      }

      public void HandleImpression(object sender, ImpressionData impressionData)
      {
          // Called when an impression is recorded for an ad.
      }

      public void HandleRewarded(object sender, Reward args)
      {
          // Called when the user can be rewarded with {args.type} and {args.amount}.
      }

      public void DestroyRewardedAd()
      {
          if (rewardedAd != null)
          {
              rewardedAd.Destroy();
              rewardedAd = null;
          }
      }
  }
  ```

{% endlist %}

## Additional resources {#resources}

* <!-- source: en/dev/_includes/github-pubdev-links.md -->
  Link to [GitHub](https://github.com/yandexmobile/yandex-ads-unity-plugin).
  <!-- endsource: en/dev/_includes/github-pubdev-links.md -->
