Rewarded Ads
Rewarded ads let you offer users in-app items—such as continued gameplay, virtual currency, or other rewards—in exchange for their engagement with ads. Rewarded ads boost engagement because users receive a tangible benefit for their time.
The following sections show you how to load and then show a rewarded ad.
Loading a Rewarded Ad
The following code shows you how to attach listeners and load the first rewarded ad:
final String _rewarded_ad_unit_ID = Platform.isAndroid ? "«Android-ad-unit-ID»" : "«iOS-ad-unit-ID»";const int _maxExponentialRetryCount = 6;var _rewardedAdRetryAttempt = 0;
void initializeRewardedAd() {
AppLovinMAX.setRewardedAdListener(RewardedAdListener(onAdLoadedCallback: (ad) {
// Rewarded ad is ready to show. AppLovinMAX.isRewardedAdReady(_rewarded_ad_unit_ID) now returns 'true'. print('Rewarded ad loaded from ' + ad.networkName);
// Reset retry attempt _rewardedAdRetryAttempt = 0; }, onAdLoadFailedCallback: (adUnitId, error) { // Rewarded ad failed to load. // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds). _rewardedAdRetryAttempt = _rewardedAdRetryAttempt + 1; if (_rewardedAdRetryAttempt > _maxExponentialRetryCount) return; int retryDelay = pow(2, min(_maxExponentialRetryCount, _rewardedAdRetryAttempt)).toInt(); print('Rewarded ad failed to load with code ' + error.code.toString() + ' - retrying in ' + retryDelay.toString() + 's');
Future.delayed(Duration(milliseconds: retryDelay * 1000), () { AppLovinMAX.loadRewardedAd(_rewarded_ad_unit_ID); }); }, onAdDisplayedCallback: (ad) { ⋮ }, onAdDisplayFailedCallback: (ad, error) { ⋮ }, onAdClickedCallback: (ad) { ⋮ }, onAdHiddenCallback: (ad) { ⋮ }, onAdReceivedRewardCallback: (ad, reward) { ⋮ }));}void loadRewardedAd() { AppLovinMAX.loadRewardedAd(_rewarded_ad_unit_id);}
Showing a Rewarded Ad
To show a rewarded ad, call showRewardedAd()
:
bool isReady = (await AppLovinMAX.isRewardedAdReady(_rewarded_ad_unit_ID))!;if (isReady) { AppLovinMAX.showRewardedAd(_rewarded_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: