Rewarded video
Rewarded videos are user-initiated ads where users can earn in-app rewards in exchange for viewing a video.
You can use our demo rewarded video app as a reference project.
Display
To display rewarded video, you need to call the following code in the activity:
- Kotlin
- Java
Appodeal.show(this, Appodeal.REWARDED_VIDEO)
Appodeal.show(this, Appodeal.REWARDED_VIDEO);
The method returns a boolean value indicating whether the call to the show method was passed to the appropriate SDK.
Check If Ad Is Loaded
You can check if the ad has been loaded before showing it. This method returns a boolean value indicating whether or not the rewarded video has been loaded.
- Kotlin
- Java
Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)
Appodeal.isLoaded(Appodeal.REWARDED_VIDEO);
We recommend you always check whether an ad is available before trying to show it.
- Kotlin
- Java
if (Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)) {
Appodeal.show(this, Appodeal.REWARDED_VIDEO)
}
if (Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)) {
Appodeal.show(this, Appodeal.REWARDED_VIDEO);
}
Placements
Appodeal SDK allows you to tag each impression with different placement. To be able to use placements, you need to create them in Appodeal Dashboard. Read more about placements.
- Kotlin
- Java
Appodeal.show(this, Appodeal.REWARDED_VIDEO, "yourPlacementName")
Appodeal.show(this, Appodeal.REWARDED_VIDEO, "yourPlacementName");
If the loaded ad can't be shown in a specific placement, nothing will be shown. If auto caching is enabled, the 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:
- Kotlin
- Java
if (Appodeal.canShow(Appodeal.REWARDED_VIDEO, "yourPlacementName")) {
Appodeal.show(this, Appodeal.REWARDED_VIDEO, "yourPlacementName")
}
if (Appodeal.canShow(Appodeal.REWARDED_VIDEO, "yourPlacementName")) {
Appodeal.show(this, Appodeal.REWARDED_VIDEO, "yourPlacementName");
}
You can configure your impression logic for each placement.
If you have no placements or call Appodeal.show
with a placement that
does not exist, the impression will be tagged with default
placement
with corresponding settings applied.
Placement settings affect ONLY ad presentation, not loading or caching.
Callbacks
- Kotlin
- Java
Appodeal.setRewardedVideoCallbacks(object : RewardedVideoCallbacks {
override fun onRewardedVideoLoaded(isPrecache: Boolean) {
// Called when rewarded video is loaded
}
override fun onRewardedVideoFailedToLoad() {
// Called when rewarded video failed to load
}
override fun onRewardedVideoShown() {
// Called when rewarded video is shown
}
override fun onRewardedVideoShowFailed() {
// Called when rewarded video show failed
}
override fun onRewardedVideoClicked() {
// Called when rewarded video is clicked
}
override fun onRewardedVideoFinished(amount: Double, currency: String?) {
// Called when rewarded video is viewed until the end
}
override fun onRewardedVideoClosed(finished: Boolean) {
// Called when rewarded video is closed
}
override fun onRewardedVideoExpired() {
// Called when rewarded video is expired
}
})
Appodeal.setRewardedVideoCallbacks(new RewardedVideoCallbacks() {
@Override
public void onRewardedVideoLoaded(boolean isPrecache) {
// Called when rewarded video is loaded
}
@Override
public void onRewardedVideoFailedToLoad() {
// Called when rewarded video failed to load
}
@Override
public void onRewardedVideoShown() {
// Called when rewarded video is shown
}
@Override
public void onRewardedVideoShowFailed() {
// Called when rewarded video show failed
}
@Override
public void onRewardedVideoClicked() {
// Called when rewarded video is clicked
}
@Override
public void onRewardedVideoFinished(double amount, String name) {
// Called when rewarded video is viewed until the end
}
@Override
public void onRewardedVideoClosed(boolean finished) {
// Called when rewarded video is closed
}
@Override
public void onRewardedVideoExpired() {
// Called when rewarded video is expired
}
});
All callbacks are called on the main thread.
Manual Caching
By default, auto caching is enabled: Appodeal SDK starts to load rewarded videos right after the initialization method is called.
The next rewarded videos ad starts to load after the previous one has been closed.
To disable automatic caching for rewarded videos, use the code below before SDK initialization:
- Kotlin
- Java
Appodeal.setAutoCache(Appodeal.REWARDED_VIDEO, false)
Appodeal.setAutoCache(Appodeal.REWARDED_VIDEO, false);
To cache rewarded video use:
- Kotlin
- Java
Appodeal.cache(this, Appodeal.REWARDED_VIDEO)
Appodeal.cache(this, Appodeal.REWARDED_VIDEO);
Read more on manual caching in our FAQ.
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 Appodeal.setUserID("User#123")
method before SDK initialization.
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.
Get Reward Data For Placement
To get the reward data set for a specific placement use the following method before showing the rewarded video:
- Kotlin
- Java
val reward: Reward = Appodeal.getReward("yourPlacementName")
val amount: Double = reward.amount
val currency: String? = reward.currency
Reward reward = Appodeal.getReward("yourPlacementName");
double amount = reward.getAmount();
String currency = reward.getCurrency();
Check If Ad Is Initialized
To check if rewarded video was initialized, you can use the method:
- Kotlin
- Java
Appodeal.isInitialized(Appodeal.REWARDED_VIDEO)
Appodeal.isInitialized(Appodeal.REWARDED_VIDEO);
Returns true
, if the rewarded video was initialized.
Check If Autocache Is Enabled
To check if autocache is enabled for rewarded video, you can use the method:
- Kotlin
- Java
Appodeal.isAutoCacheEnabled(Appodeal.REWARDED_VIDEO)
Appodeal.isAutoCacheEnabled(Appodeal.REWARDED_VIDEO);
Returns true
, if autocache is enabled for rewarded video.
Get Predicted eCPM
This method returns the expected eCPM for the cached ad. The amount is calculated based on historical data for the current ad unit.
- Kotlin
- Java
Appodeal.getPredictedEcpm(Appodeal.REWARDED_VIDEO)
Appodeal.getPredictedEcpm(Appodeal.REWARDED_VIDEO);
Mute Videos If Call Volume Is Muted
You can mute the sound in a rewarded video using the method:
- Kotlin
- Java
Appodeal.muteVideosIfCallsMuted(true)
Appodeal.muteVideosIfCallsMuted(true);
This method works if the user's device has silent mode or only vibration enabled.
Check Viewability
You can always check in logs if show was tracked and your ad is visible.
You will see the RewardedVideo [Notify Shown] log if show was tracked successfully.
- Log
Appodeal com.example.app D RewardedVideo [Notify Shown]