The Unity LevelPlay Rewarded is a full-screen ad unit, usually served at natural transition points during the app lifecycle.
Prerequisites
- Ensure that you have correctly integrated the ironSource SDK into your application. Integration is outlined here.
- Ensure that you initialize the SDK using LevelPlay Initialization API.
- Find the AdUnitID in LevelPlay dashboard.
Create Rewarded Ad Object
The creation of the Rewarded ad object must be performed after receiving the onInitSuccess callback.
The object is a reusable instance that can handle multiple loads and shows throughout the session. After creation, it should be used to load and show ads for the same ad unit.
For more advanced implementations, you may create multiple Rewarded ad objects if necessary.
LevelPlayRewardedAd mRewardedAd = new LevelPlayRewardedAd("adUnitId");
val mRewardedAd = LevelPlayRewardedAd("adUnitId")
Set Rewarded Listener
Implement the LevelPlayRewardedAdListener in your code to get informed of ad delivery.
- It is recommended to set the listener before loading the Rewarded ad.
- Each Rewarded ad should have its own listener implementation.
- Callbacks run on the main thread.
// Create the Rewarded ad object LevelPlayRewardedAd mRewardedAd = new LevelPlayRewardedAd("adUnitId"); mRewardedAd.setListener(new LevelPlayRewardedAdListener() { @Override public void onAdLoaded(LevelPlayAdInfo levelPlayAdInfo) { // Ad was loaded successfully } @Override public void onAdLoadFailed(LevelPlayAdError levelPlayAdError) { // Ad load failed } @Override public void onAdDisplayed(LevelPlayAdInfo levelPlayAdInfo) { // Ad was displayed and visible on screen } @Override public void onAdRewarded(@NonNull LevelPlayReward reward, @NonNull LevelPlayAdInfo adInfo) { // Ad reward received } @Override public void onAdDisplayFailed(LevelPlayAdError levelPlayAdError, LevelPlayAdInfo levelPlayAdInfo) { // Ad fails to be displayed // Optional } @Override public void onAdClicked(LevelPlayAdInfo levelPlayAdInfo) { // Ad was clicked // Optional } @Override public void onAdClosed(LevelPlayAdInfo levelPlayAdInfo) { // Ad was closed // Optional } @Override public void onAdInfoChanged(LevelPlayAdInfo levelPlayAdInfo) { // Called after the ad info is updated. Available when another Rewarded ad has loaded, and includes a higher CPM/Rate // Optional } }); </Tab> <Tab title="Kotlin"> ```kotlin // Create the Rewarded ad object val mRewardedAd = LevelPlayRewardedAd("adUnitId") mRewardedAd.setListener(object : LevelPlayRewardedAdListener { override fun onAdLoaded(levelPlayAdInfo: LevelPlayAdInfo) { // Ad was loaded successfully } override fun onAdLoadFailed(levelPlayAdError: LevelPlayAdError) { // Ad load failed } override fun onAdDisplayed(levelPlayAdInfo: LevelPlayAdInfo) { // Ad was displayed and visible on screen } override fun onAdRewarded(reward: LevelPlayReward, adInfo: LevelPlayAdInfo) { // Ad reward received } override fun onAdDisplayFailed(levelPlayAdError: LevelPlayAdError, levelPlayAdInfo: LevelPlayAdInfo) { // Ad fails to be displayed // Optional } override fun onAdClicked(levelPlayAdInfo: LevelPlayAdInfo) { // Ad was clicked // Optional } override fun onAdClosed(levelPlayAdInfo: LevelPlayAdInfo) { // Ad was closed // Optional } override fun onAdInfoChanged(levelPlayAdInfo: LevelPlayAdInfo) { // Called after the ad info is updated. Available when another Rewarded ad has loaded, and includes a higher CPM/Rate // Optional } }) ``` </Tab> </Tabs> #### LevelPlay Ad Info The **LevelPlayAdInfo** parameter includes information about the loaded ad. Learn more about its implementation and available fields [here](https://developers.is.com/ironsource-mobile/android/levelplay-listener-adinfo-integration/). ## Load Rewarded Ad To load a Rewarded ad use **loadAd**. <Tabs> <Tab title="Java"> ```java mRewardedAd.loadAd(); </Tab> <Tab title="Kotlin"> ```kotlin mRewardedAd.loadAd()
Show Rewarded Ad
Show an Rewarded ad after you receive the onAdLoaded callback using the LevelPlayRewardedAdListener APIs.
- It is required to share Activity.
- If using placements, pass the placement name in the showAd API as shown in the Placements section below.
- After the ad has been successfully displayed to the user, you can load another ad by repeating the loading step.
public void showRewardedAd() { // Check that ad is ready if (mRewardedAd.isAdReady()) { // Show ad mRewardedAd.showAd(this); } } </Tab> <Tab title="Kotlin"> ```kotlin fun showRewardedAd() { // Check that ad is ready if (mRewardedAd.isAdReady()) { // Show ad mRewardedAd.showAd(this) } } ``` </Tab> </Tabs> #### Check Ad is Ready To avoid show failures, and to make sure the ad could be displayed correctly, we recommend using the following API before calling the **showAd** API. **isAdReady** – returns true if ad was loaded successfully and ad unit is not capped, or false otherwise. **isPlacementCapped** – returns true when a valid placement is capped. If the placement is not valid, or not capped, this API will return false. <Tabs> <Tab title="Java"> ```java // Check that ad is ready and that the placement is not capped if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) { mRewardedAd.showAd(this, placementName); } </Tab> <Tab title="Kotlin"> ```kotlin // Check that ad is ready and that the placement is not capped if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) { mRewardedAd.showAd(this, placementName) }
Placements
We support placements pacing and capping for Rewarded on the LevelPlay dashboard.
If placements are set up for Rewarded ads, call the showAd method to serve the ad for a specific placement.
public void showRewardedAdWithPlacement() { // Check that ad is ready and that the placement is not capped if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) { // Show ad with placement mRewardedAd.showAd(this, placementName); } } </Tab> <Tab title="Kotlin"> ```kotlin fun showRewardedAdWithPlacement(placementName: String) { // Check that ad is ready and that the placement is not capped if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) { // Show ad with placement mRewardedAd.showAd(this, placementName) } }
Reward the User
The LevelPlay SDK will fire the onAdRewarded each time the user successfully completes a video.
The onAdRewarded and onAdClosed are asynchronous. Make sure to set up your listener to grant rewards even in cases where onAdRewarded is fired after the onAdClosed.
@override public void onAdRewarded(@NonNull LevelPlayReward reward, @NonNull LevelPlayAdInfo adInfo) { // Implement logic to grant the reward to the user String name = reward.getName(); int amount = reward.getAmount(); }
override fun onAdRewarded(reward: LevelPlayReward, adInfo: LevelPlayAdInfo) { // Implement logic to grant the reward to the user val name: String = reward.name val amount: Int = reward.amount }
Full Implementation Example of Rewarded Ads
public class RewardedAdActivity extends Activity implements LevelPlayRewardedAdListener { private LevelPlayRewardedAd mRewardedAd; void createRewardedAd() { mRewardedAd = new LevelPlayRewardedAd("adUnitId"); mRewardedAd.setListener(this); } void loadRewardedAd() { // Load or reload the ad mRewardedAd.loadAd(); } void showRewardedAd() { if(mRewardedAd.isAdReady()) { mRewardedAd.showAd(this); } } void showRewardedAd(@NonNull String placementName) { // Check that ad is ready and that the placement is not capped if(mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) { mRewardedAd.showAd(this, placementName); } } // LevelPlayRewardedAdListener methods @Override public void onAdLoaded(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdLoadFailed(@NonNull LevelPlayAdError error) {} @Override public void onAdDisplayed(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdClosed(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdClicked(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdDisplayFailed(@NonNull LevelPlayAdError error, @NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdInfoChanged(@NonNull LevelPlayAdInfo adInfo) {} @Override public void onAdRewarded(@NonNull LevelPlayReward reward, @NonNull LevelPlayAdInfo adInfo) {} }
class RewardedAdActivity : Activity(), LevelPlayRewardedAdListener { private lateinit var mRewardedAd: LevelPlayRewardedAd fun createRewardedAd() { mRewardedAd = LevelPlayRewardedAd("adUnitId") mRewardedAd.setListener(this) } fun loadRewardedAd() { mRewardedAd.loadAd() } fun showRewardedAd() { if (mRewardedAd.isAdReady()) { mRewardedAd.showAd(this) } } fun showRewardedAd(placementName: String) { // Check that ad is ready and that the placement is not capped if (mRewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped(placementName)) { mRewardedAd.showAd(this, placementName) } } // LevelPlayRewardedAdListener methods override fun onAdLoaded(adInfo: LevelPlayAdInfo) {} override fun onAdLoadFailed(error: LevelPlayAdError) {} override fun onAdInfoChanged(adInfo: LevelPlayAdInfo) {} override fun onAdDisplayed(adInfo: LevelPlayAdInfo) {} override fun onAdDisplayFailed(error: LevelPlayAdError, adInfo: LevelPlayAdInfo) {} override fun onAdClicked(adInfo: LevelPlayAdInfo) {} override fun onAdClosed(adInfo: LevelPlayAdInfo) {} override fun onAdRewarded(reward: LevelPlayReward, adInfo: LevelPlayAdInfo) {} }
LevelPlay Mediation Demo App
The Integration Demo application demonstrates how to integrate Rewarded Ad Unit APIs in your app.
Download Android Demo Application
Verify your integration with our Integration Test Suite.
Next steps
Follow our integration guides to integrate additional Rewarded Ad networks or configure additional ad formats: