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:
const REWARDED_AD_UNIT_IDS = { "android" : "«Android-ad-unit-ID»", "ios" : "«iOS-ad-unit-ID»"}
func _initialize_rewarded_ads(): var platform = OS.get_name().to_lower() # "android", "ios", etc. var ad_unit_id = adUnitsDict.get(platform)
var rewarded_listener = AppLovinMAX.RewardedAdEventListener.new() rewarded_listener.on_ad_loaded = Callable(self, "_on_rewarded_ad_loaded") rewarded_listener.on_ad_load_failed = Callable(self, "_on_rewarded_ad_load_failed") rewarded_listener.on_ad_displayed = Callable(self, "_on_rewarded_ad_displayed") rewarded_listener.on_ad_display_failed = Callable(self, "_on_rewarded_ad_display_failed") rewarded_listener.on_ad_clicked = Callable(self, "_on_rewarded_ad_clicked") rewarded_listener.on_ad_received_reward = Callable(self, "_on_rewarded_ad_received_reward") rewarded_listener.on_ad_hidden = Callable(self, "_on_rewarded_ad_hidden") AppLovinMAX.set_rewarded_ad_listener(rewarded_listener)
func _load_rewarded_ad(): var platform = OS.get_name().to_lower() # "android", "ios", etc. var ad_unit_id = adUnitsDict.get(platform)
AppLovinMAX.load_rewarded_ad(ad_unit_id)
### Rewarded Ad Callbacks
func _on_rewarded_ad_loaded(ad_unit_id: String, ad_info: AppLovinMAX.AdInfo): # Rewarded ad is ready to be shown. AppLovinMAX.is_rewarded_ad_ready(ad_unit_id) will now return 'true' print("Rewarded ad loaded from" + ad_info.network_name)
func _on_rewarded_ad_load_failed(ad_unit_id: String, errorInfo: AppLovinMAX.ErrorInfo): ⋮
func _on_rewarded_ad_displayed(ad_unit_id: String, ad_info: AppLovinMAX.AdInfo): ⋮
func _on_rewarded_ad_display_failed(ad_unit_id: String, errorInfo: AppLovinMAX.ErrorInfo, ad_info: AppLovinMAX.AdInfo): ⋮
func _on_rewarded_ad_clicked(ad_unit_id: String, ad_info: AppLovinMAX.AdInfo): ⋮
func _on_rewarded_ad_received_reward(ad_unit_id: String, ad_info: AppLovinMAX.AdInfo, reward: AppLovinMAX.Reward): ⋮
func _on_rewarded_ad_hidden(ad_unit_id: String, ad_info: AppLovinMAX.AdInfo): ⋮
Showing a Rewarded Ad
To show a rewarded ad, call show_rewarded_ad()
:
var platform = OS.get_name().to_lower() # "android", "ios", etc.var ad_unit_id = REWARDED_AD_UNIT_IDS.get(platform)
if AppLovinMAX.is_rewarded_ad_ready(ad_unit_id): AppLovinMAX.show_rewarded_ad(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: