Rewarded ads

Rewarded ads are a popular fullscreen ad format where users receive incentives for viewing ads.

Ad impressions are opt-in: for example, users can initiate them to get game bonuses or extra lives.

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

Appearance

This guide shows you how to integrate rewarded ads into a Compose Multiplatform app. Besides code samples and instructions, it also contains format-specific recommendations and links to additional resources.

Prerequisite

  1. Follow the Yandex Mobile Ads Compose Multiplatform plugin integration steps described under Quick start.
  2. Make sure that you have the latest version of the Yandex Mobile Ads Compose Multiplatform plugin. If you're using mediation, update to the most recent single build version.

Implementation

Key steps for integrating rewarded ads:

  1. Create an ad loader using rememberRewardedAdLoader().
  2. Load the ad using the loadAd() suspend function.
  3. If needed, attached a RewardedAdEventListener to the loaded ad before calling show().
  4. Serve the ad using the show() method.

Features of rewarded ad integration

If an ad fails to load because of an error in your custom handling, don't trigger a new ad request right away. If you can't avoid reloading, limit the number of attempts. This helps prevent endless failed requests during network issues.

Loading ads

Use rememberRewardedAdLoader() and call loadAd with an AdRequest containing the adUnitId as specified in the Boost interface.

Customize the request parameters using AdRequest (such as targeting, parameters, and preferredTheme). Providing extra context improves ad relevance. For more details, see Ad targeting.

Loading example:

@Composable
fun RewardedBlock(adUnitId: String) {
    val loader = rememberRewardedAdLoader()
    val scope = rememberCoroutineScope()
    var rewardedAd by remember { mutableStateOf<RewardedAd?>(null) }
    var isLoading by remember { mutableStateOf(false) }

    Button(
        onClick = {
            isLoading = true
            scope.launch {
                try {
                    rewardedAd = loader.loadAd(AdRequest(adUnitId = adUnitId))
                } catch (e: AdLoadException) {
                    // Load error: e.error (AdRequestError). Unlimited retries are not recommended.
                }
                isLoading = false
            }
        },
        enabled = !isLoading,
    ) {
        Text(if (isLoading) "Loading..." else "Load rewarded ad")
    }

    Button(
        onClick = {
            rewardedAd?.show()
            rewardedAd = null
        },
        enabled = rewardedAd != null,
    ) {
        Text("Show rewarded ad")
    }
}

For debugging, you can use 'demo-rewarded-yandex' as the adUnitId.

Displaying ads

Rewarded ads are an incentive-based format where users get a reward for watching an ad (such as an extra life or advancing to the next level in a game). The app determines the specific reward.

To track the lifecycle and grant the reward, set a RewardedAdEventListener on the RewardedAd instance before calling show().

val ad = rewardedAd ?: return
ad.setAdEventListener(
    object : RewardedAdEventListener {
        override fun onAdShown() {
            // Called when an ad is shown.
        }

        override fun onAdFailedToShow(adError: AdError) {
            // Called when an ad failed to show.
        }

        override fun onAdDismissed() {
            // Called when ad is dismissed. Preload the next rewarded ad if appropriate.
        }

        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) {
            // Grant currency: reward.type, reward.amount
        }
    },
)
ad.show()

Releasing resources

Once onAdDismissed or onAdFailedToShow fire, clear your references and load the next creative if needed. Don't store strong references to ads that have already been served.

Testing rewarded ad integration

Using demo ad units for ad testing

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.

Warning

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

For the list of all available demo ad placement IDs, see Demo ad units for testing.

Testing ad integration

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, a tool for debugging Android apps.

adb logcat -v brief '*:S YandexAds'

If the integration is successful, the following message is returned:

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.

Using demo ad units for ad testing

Use test ads to check your 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.

Warning

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

For the list of all available demo ad placement IDs, see Demo ad units for testing.

Testing ad integration

You can test your ad integration using the native Console tool.

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

YandexAds.enableLogging()

To view SDK logs, go to the Console tool and set Subsystem = com.mobile.ads.ads.sdk. You can filter logs by category or 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.

Tips

Ad preloading

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.

Call the loadAd method in advance to instantly show the ad when it's needed.

If you want to start loading the next ad immediately after the current one is shown, link this process to the onAdDismissed event.

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 ensure caching benefits your app, monitor the “Show rate” or “View rate” metrics in the Boost interface. If it's under 20%, you should probably revise your caching algorithm. The higher the percentage of impressions, the better.

Additional resources