If you like this plugin, please, rate it on Fab. Thank you!
Rewarded Ads
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.
Before you start
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.
You can create the ad object by calling:
Header:
class ULevelPlayRewardedAd;
// ...
UPROPERTY()
TObjectPtr<ULevelPlayRewardedAd> RewardedAd;
Source:
#include "LevelPlayRewardedAd.h"
// ...
RewardedAd = ULevelPlay::CreateRewardedAd(TEXT("AdUnitId"));

You can pass an optional Price Floor for your ad requests as a second parameter. If you do not require it, simply ignore it or pass 0 as a value.
RewardedAd = ULevelPlay::CreateRewardedAd(TEXT("AdUnitId"), 1.0);
Register to Rewarded Events
Get informed of ad delivery by binding functions or assigning events to the rewarded ad delegates. It's recommended to do this before loading the ad.
RewardedAd->OnAdLoaded.AddLambda([](const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdLoadFailed.AddLambda([](int32 ErrorCode, const FString& ErrorMessage){});
RewardedAd->OnAdDisplayed.AddLambda([](const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdDisplayFailed.AddLambda([](int32 ErrorCode, const FString& ErrorMessage, const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdRewarded.AddLambda([](int32 RewardAmount, const FString& RewardName, const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdClosed.AddLambda([](const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdClicked.AddLambda([](const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdInfoChanged.AddLambda([](const FLevelPlayAdInfo& AdInfo){});

Ad Info
The FLevelPlayAdInfo 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.
RewardedAd->LoadAd();

Show Rewarded Ad
Show a rewarded ad after you receive the OnAdLoaded callback.
- 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(TEXT("PlacementName"));

Check Ad is Ready
To avoid show failures, and to make sure the ad could be displayed correctly, it's 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() && !ULevelPlayRewardedAd::IsPlacementCapped(PlacementName))
{
RewardedAd->ShowAd(PlacementName);
}

Placements
LevelPlay supports 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.
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.
RewardedAd->OnAdRewarded.AddLambda([](int32 RewardAmount, const FString& RewardName, const FLevelPlayAdInfo& AdInfo)
{
UE_LOG(LogTemp, Display, TEXT("Ad Completed: %s, Reward: %s - %d"), *AdInfo.PlacementName, *RewardName, RewardAmount);
});
Full Implementation Example of Rewarded Ads
Header:
class ULevelPlayRewardedAd;
// ...
UPROPERTY()
TObjectPtr<ULevelPlayRewardedAd> RewardedAd;
Source:
#include "LevelPlayRewardedAd.h"
// ...
RewardedAd = ULevelPlay::CreateRewardedAd(TEXT("AdUnitId"));
RewardedAd->OnAdLoaded.AddLambda([](const FLevelPlayAdInfo& AdInfo)
{
if (RewardedAd->IsAdReady())
{
RewardedAd->ShowAd();
}
});
RewardedAd->OnAdLoadFailed.AddLambda([](int32 ErrorCode, const FString& ErrorMessage){});
RewardedAd->OnAdDisplayed.AddLambda([](const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdDisplayFailed.AddLambda([](int32 ErrorCode, const FString& ErrorMessage, const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdRewarded.AddLambda([](int32 RewardAmount, const FString& RewardName, const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdClosed.AddLambda([](const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdClicked.AddLambda([](const FLevelPlayAdInfo& AdInfo){});
RewardedAd->OnAdInfoChanged.AddLambda([](const FLevelPlayAdInfo& AdInfo){});
RewardedAd->LoadAd();
Done!
You are now all set up to serve rewarded ads in your application. Verify your integration with Integration Test Suite.