Rewarded Ads
Loading a Rewarded Ad
The following code shows you how to attach listeners and load the first rewarded ad:
import { RewardedAd } from 'react-native-applovin-max';
const REWARDED_AD_UNIT_ID = Platform.select({ android: '«android-ad-unit-ID»', ios: '«ios-ad-unit-ID»',});const MAX_EXPONENTIAL_RETRY_COUNT = 6;const retryAttempt = useRef(0);
const initializeRewardedAds = () => { RewardedAd.addAdLoadedEventListener((adInfo: AdInfo) => { // Rewarded ad is ready to show. AppLovinMAX.isInterstitialReady(REWARDED_AD_UNIT_ID) now returns 'true'
// Reset retry attempt retryAttempt.current = 0; }); RewardedAd.addAdLoadFailedEventListener((errorInfo: AdLoadFailedInfo) => { // Rewarded ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt.current += 1; if (retryAttempt.current > MAX_EXPONENTIAL_RETRY_COUNT) return; const retryDelay = Math.pow(2, Math.min(MAX_EXPONENTIAL_RETRY_COUNT, retryAttempt.current));
console.log('Rewarded ad failed to load - retrying in ' + retryDelay + 's');
setTimeout(() => { loadRewardedAd(); }, retryDelay * 1000); }); RewardedAd.addAdClickedEventListener((adInfo: AdInfo) => { ... }); RewardedAd.addAdDisplayedEventListener((adInfo: AdInfo) => { ... }); RewardedAd.addAdFailedToDisplayEventListener((adInfo: AdDisplayFailedInfo) => { // Rewarded ad failed to display. AppLovin recommends that you load the next ad loadRewardedAd(); }); RewardedAd.addAdHiddenEventListener((adInfo: AdInfo) => { loadRewardedAd(); }); RewardedAd.addAdReceivedRewardEventListener((adInfo: AdRewardInfo) => { // Rewarded ad displayed and user should receive the reward });
// Load the first rewarded ad loadRewardedAd();}
const loadRewardedAd = () => { RewardedAd.loadAd(REWARDED_AD_UNIT_ID);}
Showing a Rewarded Ad
To show a rewarded ad, call showAd()
:
const isRewardedAdReady = await RewardedAd.isAdReady(«ad-unit-ID»);if (isRewardedAdReady) { RewardedAd.showAd(«ad-unit-ID»);}
S2S Rewarded Callbacks
You can receive callbacks to your currency server. To learn how, see the MAX S2S Rewarded Callback API guide. Then update the Server Side Callback URL in your Edit Ad Unit page.
Setting the Amount and Currency for a Rewarded Ad
To set the reward amount and currency:
- Click Add S2S Reward Callback in your Edit Ad Unit page:
- Add the Server Side Callback URL, Reward Amount, and Rewarded Currency Name: