跳转到内容

Rewarded Ads

此内容尚不支持你的语言。

Loading a Rewarded Ad

The following code shows you how to attach listeners and load the first rewarded ad:

var rewardedAdUnitId:String = "«ad-unit-ID»";
var retryAttempt:Number;
private function initializeRewardedAds():void
{
// Attach event callbacks
AppLovinMAXEvents.setRewardedAdLoadedEvent(onRewardedAdLoaded);
AppLovinMAXEvents.setRewardedAdLoadFailedEvent(onRewardedAdFailedToLoad);
AppLovinMAXEvents.setRewardedAdDisplayedEvent(onRewardedAdDisplayed);
AppLovinMAXEvents.setRewardedAdFailedToDisplayEvent(onRewardedAdFailedToDisplay);
AppLovinMAXEvents.setRewardedAdClickedEvent(onRewardedAdClicked);
AppLovinMAXEvents.setRewardedAdReceivedRewardEvent(onRewardedAdReceivedReward);
AppLovinMAXEvents.setRewardedAdHiddenEvent(onRewardedAdHidden);
// Load the first rewarded ad
loadRewardedAd();
}
private function loadRewardedAd():void
{
AppLovinMAX.loadRewardedAd(rewardedAdUnitId);
}
private function onRewardedAdLoaded(adEventInfo:AdEventInfo):void
{
// Rewarded ad is ready for you to show. MaxSdk.IsRewardedAdReady(adUnitId) now returns 'true'.
// Reset retry attempt
retryAttempt = 0;
}
private function onRewardedAdFailedToLoad(adEventInfo:AdEventInfo):void
{
// 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++;
var retryDelay:Number = Math.pow(2, Math.min(6, retryAttempt));
var timer:Timer = new Timer(retryDelay, 1);
timer.addEventListener(TimerEvent.TIMER, loadInterstitial);
timer.start();
}
private function onRewardedAdDisplayed(adEventInfo:AdEventInfo):void {}
private function onRewardedAdFailedToDisplay(adEventInfo:AdEventInfo):void
{
// Rewarded ad failed to display. AppLovin recommends that you load the next ad.
loadRewardedAd();
}
private function onRewardedAdClicked(adEventInfo:AdEventInfo):void {}
private function onRewardedAdReceivedReward(adEventInfo:AdEventInfo, reward:AppLovinMAXReward):void
{
// The rewarded ad displayed and the user should receive the reward.
}
private function onRewardedAdHidden(adEventInfo:AdEventInfo):void
{
// Rewarded ad is hidden. Pre-load the next ad
loadRewardedAd();
}

Showing a Rewarded Ad

To show a rewarded ad, call showRewardedAd():

if (AppLovinMAX.isRewardedAdReady(«ad-unit-ID»))
{
AppLovinMAX.showRewardedAd(«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:

  1. Click Add S2S Reward Callback in your Edit Ad Unit page: Ad Type: ☐App Open, ☐Banner, ☐Interstitial, ☐MRec, ☐Native, ☑Rewarded. Add S2S Reward Callback.
  2. Add the Server Side Callback URL, Reward Amount, and Rewarded Currency Name: Ad Type: ☐App Open, ☐Banner, ☐Interstitial, ☐MRec, ☐Native, ☑Rewarded. Hide Callback Settings. Server Side Callback URL form field. Reward Amount form field. Rewarded Currency Name form field. AppLovin Event Key form field.