Rewarded ads

Rewarded ads are a full-screen ad format where users get bonuses or other rewards (for example, in-game coins, retries, access to premium features, and so on) for watching ads.

Note

It's the user who decides whether to watch the ad or skip it, receiving a reward only if they watch it to the end.

Entity

Description

onAdFailedToShow

If onAdFailedToShow() returns an error, don't attempt to load a new ad again using the same method.

adUnitId

Use:

  • Development mode to work with demo ad units.

  • Production mode to work with R-M-XXXXXX-Y (for the actual ID, check the Yandex Advertising Network interface). R-M-XXXXXX-Y is a template for your actual ad unit ID that will be used to receive various creatives.

Example of creating a rewarded ad

import React, { useState } from 'react';
import { Alert, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { AdRequestConfiguration, RewardedAd, RewardedAdLoader } from 'yandex-mobile-ads';

const REWARDED_AD_UNIT_ID = 'demo-rewarded-yandex'; // Replace with your ID
const REWARD = {
    amount: 50,
    type: 'coins',
}

export default function RewardedView() {
  const [isLoaded, setIsLoaded] = useState(false);
  const [isLoading, setIsLoading] = useState(false);
  const [rewardedAd, setRewardedAd] = useState<RewardedAd | null>(null);

  const loadAd = async () => {
    try {
      setIsLoading(true);

      // 1. Create a loader
      const loader = await RewardedAdLoader.create();

      // 2. Create a request configuration
      const adRequestConfiguration = new AdRequestConfiguration({
        adUnitId: REWARDED_AD_UNIT_ID,
      });

      // 3. Load an ad
      const ad = await loader.loadAd(adRequestConfiguration);

      console.log('Rewarded ad loaded');

      // 4. Configure event handlers
      ad.onAdShown = () => {
        console.log('Rewarded ad shown');
      };

      ad.onAdDismissed = () => {
        console.log('Rewarded ad dismissed');
        setIsLoaded(false);
        setRewardedAd(null);
      };

      ad.onAdClicked = () => {
        console.log('Rewarded ad clicked');
      };

      ad.onAdImpression = (impressionData) => {
        console.log('Rewarded impression:', impressionData);
      };

      ad.onAdFailedToShow = (error) => {
        console.error('Rewarded failed to show:', error);
        Alert.alert('Ad Failed to Show', JSON.stringify(error));
        setIsLoaded(false);
      };

      ad.onRewarded = () => {
        Alert.alert('🎉 Reward!', `You earned ${REWARD.amount} ${REWARD.type}`);
        console.log('User rewarded:', REWARD);
      };

      setRewardedAd(ad);
      setIsLoaded(true);
      setIsLoading(false);

    } catch (error) {
      console.error('Failed to load rewarded ad:', error);
      Alert.alert('Ad Failed to Load', JSON.stringify(error));
      setIsLoading(false);
      setIsLoaded(false);
    }
  };

  const showAd = () => {
    if (rewardedAd && isLoaded) {
      rewardedAd.show();
    } else {
      Alert.alert('Ad not ready', 'Please load the ad first');
    }
  };

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Rewarded Ad</Text>

      <TouchableOpacity
        style={[styles.button, isLoading && styles.buttonDisabled]}
        onPress={loadAd}
        disabled={isLoading}
      >
        <Text style={styles.buttonText}>
          {isLoading ? 'Loading...' : 'Load Ad'}
        </Text>
      </TouchableOpacity>

      <TouchableOpacity
        style={[styles.button, styles.showButton, !isLoaded && styles.buttonDisabled]}
        onPress={showAd}
        disabled={!isLoaded}
      >
        <Text style={styles.buttonText}>Show Ad & Get Reward</Text>
      </TouchableOpacity>

      <Text style={styles.status}>
        {isLoaded ? '✅ Ad Ready' : '❌ Ad Not Loaded'}
      </Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#f5f5f5',
    padding: 20,
  },
  title: {
    fontSize: 24,
    fontWeight: 'bold',
    marginBottom: 40,
  },
  button: {
    backgroundColor: '#007AFF',
    paddingVertical: 15,
    paddingHorizontal: 40,
    borderRadius: 10,
    marginVertical: 10,
    width: '80%',
    alignItems: 'center',
  },
  showButton: {
    backgroundColor: '#34C759',
  },
  buttonDisabled: {
    backgroundColor: '#ccc',
  },
  buttonText: {
    color: '#fff',
    fontSize: 18,
    fontWeight: '600',
  },
  status: {
    marginTop: 30,
    fontSize: 16,
    color: '#666',
  },
});

Checking integration

You can test the performance of ad formats using our demo project.