Rewarded ad

Rewarded ads are a popular full-screen ad format, where the user receives a reward for viewing the ad.

The display of this ad type is activated by the user, for instance, to receive a bonus or additional life in a game.

High user motivation makes this ad format the most popular and profitable in free apps.

Appearance

This guide shows how to integrate rewarded ads into an Android app using the Jetpack Compose extension. In addition to code examples and instructions, it provides recommendations on using this ad format and links to additional resources.

Prerequisite

  1. Follow the SDK integration steps described in Quick start.
  2. Initialize your ad SDK in advance.
  3. Make sure you're running the latest Yandex Mobile Ads SDK version. If you're using mediation, make sure you're also running the latest version of the unified build.

To use the Compose extension, add the dependency to build.gradle.kts:

dependencies {
    implementation("com.yandex.android:mobileads:8.0.0")
    implementation("com.yandex.android:mobileads-compose:8.0.0")

    // Compose BOM (minimum 2024.01.00)
    implementation(platform("androidx.compose:compose-bom:2025.03.00"))
}

Implementation

Key steps for integrating rewarded ads:

  • Use rememberRewardedAdLoader() to create an ad loader.
  • Load the ad via the suspend function loadAd() and handle the RewardedAdLoadResult.
  • Register a listener for ad event callbacks RewardedAdEventListener.
  • Show the RewardedAd.
  • Grant the user a reward for watching the ad.

Rewarded ad integration notes

  1. All Yandex Mobile Ads SDK method calls must be made from the main thread.

  2. If you receive an error in RewardedAdLoadResult.Failure, do not attempt to load a new ad immediately. If you must retry, limit the number of reload attempts to avoid continuous failed requests and connection issues under restricted conditions.

  3. It is recommended to keep a strong reference to the ad throughout the lifetime of the screen where the ad interaction occurs.

  4. When a composable leaves the composition tree, cancelLoading() is called automatically — there is no need to explicitly release loader resources.

Loading ads

To load a rewarded ad, use rememberRewardedAdLoader(). Loading is performed via the suspend function loadAd(), which returns RewardedAdLoadResult.

To load an ad, you will need the ad unit ID obtained from the Yandex Advertising Network interface (adUnitId).

You can extend the ad request parameters via AdRequestConfiguration.Builder() by passing user interest data, page context data, location, or other additional data. Additional contextual data in the request can significantly improve ad quality. For more information, see Ad targeting.

The following example shows how to load a rewarded ad:

import com.yandex.mobile.ads.common.AdRequestConfiguration
import com.yandex.mobile.ads.compose.rememberRewardedAdLoader
import com.yandex.mobile.ads.rewarded.RewardedAdLoadResult

@Composable
fun MyScreen(activity: Activity) {
    var rewardedAd by remember { mutableStateOf<RewardedAd?>(null) }

    val loader = rememberRewardedAdLoader()

    LaunchedEffect(Unit) {
        val adRequestConfiguration = AdRequestConfiguration.Builder("your-ad-unit-id").build()
        when (val result = loader.loadAd(adRequestConfiguration)) {
            is RewardedAdLoadResult.Success -> rewardedAd = result.ad
            is RewardedAdLoadResult.Failure -> {
                // Ad failed to load with AdRequestError.
                // Attempting to load a new ad from here is strongly discouraged.
            }
        }
    }
}

Showing the ad

Rewarded advertising is an incentive-based ad format that allows the user to receive a reward for viewing the ad. The reward could be an extra life or advancing to the next level in a game. The reward format is determined at the app level.

To track rewarded ad lifecycle events and receive the reward, set the RewardedAdEventListener callback listener on the RewardedAd object.

The reward is passed directly to the onRewarded callback when the show() method is called:

@Composable
fun MyScreen(activity: Activity) {
    var rewardedAd by remember { mutableStateOf<RewardedAd?>(null) }

    val loader = rememberRewardedAdLoader()

    LaunchedEffect(Unit) {
        val adRequestConfiguration = AdRequestConfiguration.Builder("your-ad-unit-id").build()
        when (val result = loader.loadAd(adRequestConfiguration)) {
            is RewardedAdLoadResult.Success -> rewardedAd = result.ad
            is RewardedAdLoadResult.Failure -> {
                // Ad failed to load with AdRequestError.
            }
        }
    }

    LaunchedEffect(rewardedAd) {
        rewardedAd?.apply {
            setAdEventListener(object : RewardedAdEventListener {
                override fun onAdShown() {
                    // Called when ad is shown.
                }

                override fun onAdFailedToShow(adError: AdError) {
                    // Called when an RewardedAd failed to show.
                    // Now you can preload the next rewarded ad.
                    loadRewardedAd()
                }

                override fun onAdDismissed() {
                    // Called when ad is dismissed.
                    // Now you can preload the next rewarded ad.
                    loadRewardedAd()
                }

                override fun onAdClicked() {
                    // Called when a click is recorded for an ad.
                }

                override fun onAdImpression(impressionData: ImpressionData?) {
                    // Called when an impression is recorded for an ad.
                }

                override fun onRewarded(reward: Reward) {
                    // Called when the user can be rewarded.
                }
            })
            show(activity)
        }
    }
}

Testing rewarded ad integration

Using demo ad units for ad testing

We recommend using test ads to test your rewarded 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.

Warning

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

You can find the list of available demo ad placement IDs in the Demo ad units for testing section.

Testing ad integration

You can test your rewarded ad integration using the SDK's built-in analyzer.

The tool checks makes sure your rewarded ads are integrated properly and outputs a detailed report to the log. To view the report, search for the “YandexAds” keyword in the Logcat tool for Android app debugging.

adb logcat -v brief '*:S YandexAds'

If the integration is successful, you'll see this message:

adb logcat -v brief '*:S YandexAds'
mobileads$ adb logcat -v brief '*:S YandexAds'
I/YandexAds(13719): [Integration] Ad type rewarded was integrated successfully

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

Additional resources