Rewarded Video
Rewarded video is a user-initiated ad type. It allows end-users to get in-app rewards or other benefits in exchange for viewing a video ad.
You can use our demo app as a reference project.
Demo App
Check If Ad Is Loaded
You can check whether or not an ad is loaded at a certain moment. This method returns a boolean value, representing the rewarded video ad loading status.
- UPM Distribution
- Manual Distribution
Appodeal.IsLoaded(AppodealAdType.RewardedVideo);
Appodeal.isLoaded(Appodeal.REWARDED_VIDEO);
We recommend you always check whether an ad is available before trying to show it.
Example:
- UPM Distribution
- Manual Distribution
if(Appodeal.IsLoaded(AppodealAdType.RewardedVideo)) {
Appodeal.Show(AppodealShowStyle.RewardedVideo);
}
if(Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)) {
Appodeal.show(Appodeal.REWARDED_VIDEO);
}
Display
To show a rewarded video ad, you need to call the following method:
- UPM Distribution
- Manual Distribution
Appodeal.Show(AppodealShowStyle.RewardedVideo);
Appodeal.show(Appodeal.REWARDED_VIDEO);
Manual Caching
If you need more control of rewarded video ads loading use manual caching. Manual caching for rewarded video can be useful to improve display rate or decrease SDK loads when several ad types are cached.
- To disable automatic caching for rewarded video, use the code below before the SDK initialization:
- UPM Distribution
- Manual Distribution
Appodeal.SetAutoCache(AppodealAdType.RewardedVideo, false);
Appodeal.setAutoCache(Appodeal.REWARDED_VIDEO, false);
- To cache rewarded video ad manually use the following method:
- UPM Distribution
- Manual Distribution
Appodeal.Cache(AppodealAdType.RewardedVideo);
Appodeal.cache(Appodeal.REWARDED_VIDEO);
Callbacks
The callbacks are used to track different events in the lifecycle of an ad, e.g. when an ad was clicked on or closed. Follow the steps below to implement them:
- UPM Distribution
- Manual Distribution
Subscribe to the desired rewarded video event using one of the options from this guide. (you can subscribe to any number of events you want)
AppodealCallbacks.RewardedVideo.OnLoaded += (sender, args) => { };
You will find all existing rewarded video events in the example below:
public void SomeMethod()
{
AppodealCallbacks.RewardedVideo.OnLoaded += OnRewardedVideoLoaded;
AppodealCallbacks.RewardedVideo.OnFailedToLoad += OnRewardedVideoFailedToLoad;
AppodealCallbacks.RewardedVideo.OnShown += OnRewardedVideoShown;
AppodealCallbacks.RewardedVideo.OnShowFailed += OnRewardedVideoShowFailed;
AppodealCallbacks.RewardedVideo.OnClosed += OnRewardedVideoClosed;
AppodealCallbacks.RewardedVideo.OnFinished += OnRewardedVideoFinished;
AppodealCallbacks.RewardedVideo.OnClicked += OnRewardedVideoClicked;
AppodealCallbacks.RewardedVideo.OnExpired += OnRewardedVideoExpired;
}
#region RewardedVideoAd Callbacks
//Called when rewarded video was loaded (precache flag shows if the loaded ad is precache).
private void OnRewardedVideoLoaded(object sender, AdLoadedEventArgs e)
{
Debug.Log($"[APDUnity] [Callback] OnRewardedVideoLoaded(bool isPrecache:{e.IsPrecache})");
}
// Called when rewarded video failed to load
private void OnRewardedVideoFailedToLoad(object sender, EventArgs e)
{
Debug.Log("[APDUnity] [Callback] OnRewardedVideoFailedToLoad()");
}
// Called when rewarded video was loaded, but cannot be shown (internal network errors, placement settings, etc.)
private void OnRewardedVideoShowFailed(object sender, EventArgs e)
{
Debug.Log("[APDUnity] [Callback] OnRewardedVideoShowFailed()");
}
// Called when rewarded video is shown
private void OnRewardedVideoShown(object sender, EventArgs e)
{
Debug.Log("[APDUnity] [Callback] OnRewardedVideoShown()");
}
// Called when rewarded video is closed
private void OnRewardedVideoClosed(object sender, RewardedVideoClosedEventArgs e)
{
Debug.Log($"[APDUnity] [Callback] OnRewardedVideoClosed(bool finished:{e.Finished})");
}
// Called when rewarded video is viewed until the end
private void OnRewardedVideoFinished(object sender, RewardedVideoFinishedEventArgs e)
{
Debug.Log($"[APDUnity] [Callback] OnRewardedVideoFinished(double amount:{e.Amount}, string name:{e.Currency})");
}
// Called when rewarded video is clicked
private void OnRewardedVideoClicked(object sender, EventArgs e)
{
Debug.Log("[APDUnity] [Callback] OnRewardedVideoClicked()");
}
//Called when rewarded video is expired and can not be shown
private void OnRewardedVideoExpired(object sender, EventArgs e)
{
Debug.Log("[APDUnity] [Callback] OnRewardedVideoExpired()");
}
#endregion
- Extend your class with
IRewardedVideoAdListener
interface:
class SomeClassName : IRewardedVideoAdListener {}
- Implement all required callback methods:
#region Rewarded Video callback handlers
//Called when rewarded video was loaded (precache flag shows if the loaded ad is precache).
public void onRewardedVideoLoaded(bool isPrecache)
{
Debug.Log("RewardedVideo loaded");
}
// Called when rewarded video failed to load
public void onRewardedVideoFailedToLoad()
{
Debug.Log("RewardedVideo failed to load");
}
// Called when rewarded video was loaded, but cannot be shown (internal network errors, placement settings, etc.)
public void onRewardedVideoShowFailed()
{
Debug.Log("RewardedVideo show failed");
}
// Called when rewarded video is shown
public void onRewardedVideoShown()
{
Debug.Log("RewardedVideo shown");
}
// Called when reward video is clicked
public void onRewardedVideoClicked()
{
Debug.Log("RewardedVideo clicked");
}
// Called when rewarded video is closed
public void onRewardedVideoClosed(bool finished)
{
Debug.Log("RewardedVideo closed");
}
// Called when rewarded video is viewed until the end
public void onRewardedVideoFinished(double amount, string name)
{
Debug.Log("RewardedVideo finished");
}
//Called when rewarded video is expired and can not be shown
public void onRewardedVideoExpired()
{
Debug.Log("RewardedVideo expired");
}
#endregion
- Call the following method:
Appodeal.setRewardedVideoCallbacks(this);
All callbacks are called on native main threads that do not match the main thread of the Unity. If you need to receive callbacks in the main Unity thread follow our Callback Usage Guide.
Placements
Appodeal SDK allows you to tag each impression with different placement. To use placements, you need to create placements in Appodeal Dashboard. Read more about placements.
To show an ad with placement, you have to call show method with specifying placement's name:
- UPM Distribution
- Manual Distribution
Appodeal.Show(AppodealShowStyle.RewardedVideo, "placementName");
Appodeal.show(Appodeal.REWARDED_VIDEO, "placementName");
If the loaded ad can’t be shown for a specific placement, nothing will be shown. If auto caching is enabled, sdk will start to cache another ad, which can affect display rate. To save the loaded ad for future use (for instance, for another placement) check if the ad can be shown before calling show method:
- UPM Distribution
- Manual Distribution
if(Appodeal.CanShow(AppodealAdType.RewardedVideo, "placementName")) {
Appodeal.Show(AppodealShowStyle.RewardedVideo, "placementName");
}
You can configure your impression logic for each placement.
If you have no placements, or call Appodeal.Show()
method with a placement that does not exist, the impression
will be tagged with default
placement name and its settings will be applied.
if(Appodeal.canShow(Appodeal.REWARDED_VIDEO, "placementName")) {
Appodeal.show(Appodeal.REWARDED_VIDEO, "placementName");
}
You can configure your impression logic for each placement.
If you have no placements, or call Appodeal.show()
method with a placement that does not exist, the impression
will be tagged with default
placement name and its settings will be applied.
Server-to-Server Callbacks
To secure your apps economy we offer S2S reward callbacks. To validate each reward, you need to set up a callback URL on your server that will receive the reward information. We will pass the user data to your callback URL, which you will need to validate and adjust the user balance accordingly.
-
Create the reward callback URL on your server that will receive the reward information.
-
Fill the created URL and the encryption key in the app settings in your dashboard.
-
The reward callback will be sent to your URL using GET request with two parameters:
{http:/example.com/reward}?data1={data1}&data2={data2}
-
Your URL should decrypt the data and validate it.
-
Check
impression_id
for uniqueness and store it in your system to prevent duplicate transactions.
To set user ID, use the following method before SDK initialization:
- UPM Distribution
- Manual Distribution
Appodeal.SetUserId("user#123");
Appodeal.setUserId("user#123");
We offer sample scripts in Go, PHP, Ruby, Java, Node.js, Python 3 and C# to decrypt the data. If you need samples in other languages, please contact our support team and we will provide them to you.
Sample in PHP: reward.php.
Sample in Ruby: reward.rb.
Sample in Java: reward.java.
Sample in Node.js: reward.js.
Sample in Python 3: reward.py.
Sample in C#: reward.cs.
Sample in Go: reward.go.
Getting Reward Data For A Specific Placement
To get reward data and notify your users of it before the video ad is shown, use this method. It returns
KeyValuePair
with the currency type and amount of the reward.
- UPM Distribution
- Manual Distribution
Appodeal.GetRewardParameters("placementName");
Appodeal.getRewardParameters("placementName");
Get Predicted eCPM
This method returns expected eCPM for a currently cached advertisement. The amount is calculated based on historical data for the current ad unit.
- UPM Distribution
- Manual Distribution
Appodeal.GetPredictedEcpm(AppodealAdType.RewardedVideo);
Appodeal.getPredictedEcpm(Appodeal.REWARDED_VIDEO);
Mute Video Ads
You can mute video ads if calls are muted on the device. For muting you need to call the following method before initializing the SDK.
- UPM Distribution
- Manual Distribution
Appodeal.MuteVideosIfCallsMuted(true);
Appodeal.muteVideosIfCallsMuted(true);