Rewarded Ads Integration for Unity Package
The Unity LevelPlay Rewarded Ad is a user-initiated ad unit that offers users the opportunity to engage with full-screen ads in exchange for in-app rewards, enhancing engagement while maintaining a positive user experience.
- Make sure that you have correctly integrated the LevelPlay Unity package into your application. Integration is outlined here.
- Make sure to initialize the SDK using LevelPlay Initialization API.
- You can find the AdUnitID in LevelPlay dashboard. Learn more here.
- This documentation is relevant for SDK 8.5.0+. Documentation for legacy Rewarded APIs (SDK 8.5.0 and below) can be found here.
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. Once created, 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.
// Create Rewarded ad object
RewardedAd = new LevelPlayRewardedAd(RewardedAdUnitId);
Register to Rewarded Events
Implement the LevelPlayRewardedAdListener in your code to get informed of ad delivery.
- It is recommended to set the listener before loading the rewarded ad.
- Please note that each rewarded ad should have its own listener implementation.
- Callbacks run on the main thread.
// Register to Rewarded events
RewardedAd.OnAdLoaded += RewardedOnAdLoadedEvent;
RewardedAd.OnAdLoadFailed += RewardedOnAdLoadFailedEvent;
RewardedAd.OnAdDisplayed += RewardedOnAdDisplayedEvent;
RewardedAd.OnAdDisplayFailed += RewardedOnAdDisplayFailedEvent;
RewardedAd.OnAdRewarded += RewardedOnAdRewardedEvent;
RewardedAd.OnAdClosed += RewardedOnAdClosedEvent;
// Optional
RewardedAd.OnAdClicked += RewardedOnAdClickedEvent;
RewardedAd.OnAdInfoChanged += RewardedOnAdInfoChangedEvent;
// Implement the events
void RewardedOnAdLoadedEvent(LevelPlayAdInfo adInfo){}
void RewardedOnAdLoadFailedEvent(LevelPlayAdError error){}
void RewardedOnAdDisplayedEvent(LevelPlayAdInfo adInfo){}
void RewardedOnAdDisplayFailedEvent(LevelPlayAdDisplayInfoError infoError){}
void RewardedOnAdRewardedEvent(LevelPlayAdInfo adInfo, LevelPlayReward adReward){}
void RewardedOnAdClosedEvent(LevelPlayAdInfo adInfo){}
void RewardedOnAdClickedEvent(LevelPlayAdInfo adInfo){}
void RewardedOnAdInfoChangedEvent(LevelPlayAdInfo adInfo){}
LevelPlay Ad Info
The LevelPlayAdInfo parameter includes information about the loaded ad.
Learn more about its implementation and available fields here.
Load Rewarded Ad
To load a rewarded ad use LoadAd.
// Load rewarded ad
RewardedAd.LoadAd();
Show Rewarded Ad
Show a rewarded ad after you receive the OnAdLoaded callback using the LevelPlayRewardedAdListener APIs.
- If using placements, pass the placement name in the ShowAd API as shown in the Placements section below.
- Once the ad has been successfully displayed to the user, you can load another ad by repeating the loading step.
// Show ad without placement
RewardedAd.ShowAd();
// Show ad with placement
RewardedAd.ShowAd(placementName: "placementName");
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.
// Check that ad is ready and that the placement is not capped
if (RewardedAd.IsAdReady() && !LevelPlayRewardedAd.IsPlacementCapped(placementName))
{
RewardedAd.ShowAd(placementName);
}
Placements
We support placements pacing and capping for rewarded ad on the LevelPlay dashboard.
If placements are set up for rewarded ads, call the ShowAd method to serve the ad for a specific placement.
// Check that ad is ready and that the placement is not capped
if (RewardedAd.IsAdReady() && !LevelPlayRewardedAd.IsPlacementCapped(placementName))
{
RewardedAd.ShowAd(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.
// Subscribe to the OnAdRewarded event
RewardedAd.OnAdRewarded += (adInfo, adReward) =>
{
// Grant the reward to the user
Debug.Log($"Ad Completed: {adInfo.PlacementName}, Reward: {adReward.Name} - {adReward.Amount}");
GrantReward(adReward.Name, adReward.Amount);
};
// Example method to process the reward
private void GrantReward(string rewardName, int rewardAmount)
{
// TODO: Implement logic to grant the reward to the user
Debug.Log($"Granting reward: {rewardName} with amount: {rewardAmount}");
}
Full Implementation Example of Rewarded Ads
public class RewardedAdSample {
private LevelPlayRewardedAd RewardedAd
void CreateRewardedAd() {
//Create RewardedAd instance
RewardedAd= new LevelPlayRewardedAd("RewardedAdUnitId");
//Subscribe RewardedAd events
RewardedAd.OnAdLoaded += RewardedOnAdLoadedEvent;
RewardedAd.OnAdLoadFailed += RewardedOnAdLoadFailedEvent;
RewardedAd.OnAdDisplayed += RewardedOnAdDisplayedEvent;
RewardedAd.OnAdDisplayFailed += RewardedOnAdDisplayFailedEvent;
RewardedAd.OnAdClicked += RewardedOnAdClickedEvent;
RewardedAd.OnAdClosed += RewardedOnAdClosedEvent;
RewardedAd.OnAdRewarded += RewardedOnAdRewarded;
RewardedAd.OnAdInfoChanged += RewardedOnAdInfoChangedEvent;
}
void LoadRewardedAd() {
//Load or reload RewardedAd
RewardedAd.LoadAd();
}
void ShowRewardedAd() {
//Show RewardedAd, check if the ad is ready before showing
if (RewardedAd.IsAdReady()) {
RewardedAd.ShowAd();
}
}
//Implement RewardedAd events
void RewardedOnAdLoadedEvent(LevelPlayAdInfo adInfo) { }
void RewardedOnAdLoadFailedEvent(LevelPlayAdError ironSourceError) { }
void RewardedOnAdClickedEvent(LevelPlayAdInfo adInfo) { }
void RewardedOnAdDisplayedEvent(LevelPlayAdInfo adInfo) { }
void RewardedOnAdDisplayFailedEvent(LevelPlayAdDisplayInfoError adInfoError) { }
void RewardedOnAdClosedEvent(LevelPlayAdInfo adInfo) { }
void RewardedOnAdRewarded(LevelPlayAdInfo adInfo, LevelPlayReward adReward)
void RewardedOnAdInfoChangedEvent(LevelPlayAdInfo adInfo) { }
}
LevelPlay Mediation Demo App
The Integration Demo application demonstrates how to integrate rewarded Ad Unit APIs in your app.
Download Unity Demo Application
Done!
You are now all set up to serve rewarded ads in your application. Verify your integration with our Integration Test Suite.
Follow our integration guides to integrate additional Rewarded Ad networks or configure additional ad formats: