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 app as a reference project.
Demo App
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.
- Swift
- Objective-C
Appodeal.isReadyForShow(with: .rewardedVideo)
[Appodeal isReadyForShowWithStyle: AppodealShowStyleRewardedVideo];
We recommend you to check ad caching before trying to show it.
Display
- Swift
- Objective-C
Appodeal.showAd(.rewardedVideo, rootViewController: self)
[Appodeal showAd:AppodealShowStyleRewardedVideo rootViewController:self];
Manual Caching
By default, auto caching is enabled: Appodeal SDK starts to load Rewarded Video right after the initialization method is called.
The next Rewarded Video ad starts to load after the previous one has been closed.
To disable automatic caching for Rewarded Video, use the code below before SDK initialization:
- Swift
- Objective-C
Appodeal.setAutocache(false, types: .rewardedVideo)
[Appodeal setAutocache: NO types:AppodealAdTypeRewardedVideo];
If you need more control over Rewarded video ad loading, use manual caching. Manual caching for Rewarded videos can be useful to improve display rate or decrease SDK load when several ad types are cached.
To cache a Rewarded Video, use:
- Swift
- Objective-C
Appodeal.cacheAd(.rewardedVideo)
[Appodeal cacheAd:AppodealAdTypeRewardedVideo];
Read more on manual caching in our FAQ.
Callbacks
Callbacks are used to track different events in the lifecycle of an ad, e.g., when an ad was clicked on or closed. To get them, you need to set the delegate as follows:
- Swift
- Objective-C
// set delegate
Appodeal.setRewardedVideoDelegate(self)
// set delegate
[Appodeal setRewardedVideoDelegate:self];
Usually, the class that implements rewarded video ads is also the
delegate class. That's why the delegate property can be set to self
.
Now you can use the following callback methods:
- Swift
- Objective-C
extension YourViewController: AppodealRewardedVideoDelegate {
// Method called when rewarded video loads
//
// - Parameter precache: If precache is YES it means that precached ad loaded
func rewardedVideoDidLoadAdIsPrecache(_ precache: Bool) {
}
// Method called if rewarded video mediation failed
func rewardedVideoDidFailToLoadAd() {
}
// Method called if rewarded mediation was successful, but ready ad network can't show ad or
// ad presentation was too frequent according to your placement settings
//
// - Parameter error: Error object that indicates error reason
func rewardedVideoDidFailToPresentWithError(_ error: Error) {
}
// Method called after rewarded video start displaying
func rewardedVideoDidPresent() {
}
// Method called before rewarded video leaves screen
//
// - Parameter wasFullyWatched: boolean flag indicated that user watch video fully
func rewardedVideoWillDismissAndWasFullyWatched(_ wasFullyWatched: Bool) {
}
// Method called after fully watch of video
//
// - Warning: After call this method rewarded video can stay on screen and show postbanner
// - Parameters:
// - rewardAmount: Amount of app curency tuned via Appodeal Dashboard
// - rewardName: Name of app currency tuned via Appodeal Dashboard
func rewardedVideoDidFinish(_ rewardAmount: Float, name rewardName: String?) {
}
// Method is called when rewarded video is clicked
func rewardedVideoDidClick() {
}
// Method called when rewardedVideo did expire and can not be shown
func rewardedVideoDidExpired() {
}
}
- (void)rewardedVideoDidLoadAdIsPrecache:(BOOL)precache {
// rewarded video was loaded
}
- (void)rewardedVideoDidFailToLoadAd {
// rewarded video ad failed to load
}
- (void)rewardedVideoDidFailToPresentWithError:(NSError *)error {
// rewarded video ad was loaded but failed to present due to ad netwotk error,
// placement settings or invalid creative.
// Error object that indicates error reason
}
- (void)rewardedVideoDidPresent {
// rewarded video was presented
}
- (void)rewardedVideoWillDismissAndWasFullyWatched:(BOOL)wasFullyWatched {
// rewarded video was closed.
// wasFullyWatched boolean flag indicated that user watch video fully
}
- (void)rewardedVideoDidFinish:(float)rewardAmount name:(NSString *)rewardName {
// rewarded video finished with some reward
}
- (void)rewardedVideoDidClick {
// Method is called when rewarded video is clicked
}
- (void)rewardedVideoDidExpired {
// rewarded video did expire and could not be shown
}
All callbacks are called on the main thread.
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.
- Swift
- Objective-C
Appodeal.showAd(.rewardedVideo, forPlacement: placement, rootViewController: self)
[Appodeal showAd:AppodealShowStyleRewardedVideo forPlacement:placement rootViewController:self];
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:
- Swift
- Objective-C
Appodeal.canShow(.rewardedVideo, forPlacement: placement)
[Appodeal canShow:AppodealAdTypeRewardedVideo forPlacement:placement];
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.
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.getUserSettings(this).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.
Getting Reward Data For A Specific Placement
To get reward details (currency, name and amount) for any placement, use
the rewardForPlacement:(NSString *)placement
method:
- Swift
- Objective-C
let rewardCurrencyName = Appodeal.reward(forPlacement:"placement").currencyName
let rewardAmount = Appodeal.reward(forPlacement:"placement").amount
NSString *rewardCurrencyName = [[Appodeal rewardForPlacement:@"placement"] currencyName];
NSUInteger rewardAmount = [[Appodeal rewardForPlacement:@"placement"] amount];
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.
- Swift
- Objective-C
Appodeal.predictedEcpm(for: .rewardedVideo)
[Appodeal predictedEcpmForAdType: AppodealAdTypeRewardedVideo];
Check If Ad Is Initialized
- Swift
- Objective-C
Appodeal.isInitialized(for: .rewardedVideo)
[Appodeal isInitalizedForAdType: AppodealAdTypeRewardedVideo];
Returns true
if the Rewarded Video has been initialized.
Check If Autocache Is Enabled
- Swift
- Objective-C
Appodeal.isAutocacheEnabled(.rewardedVideo)
[Appodeal isAutocacheEnabled: AppodealAdTypeRewardedVideo];
Returns true
if autocache is enabled for Rewarded Video.
Check Viewability
You can always check in logs if show was tracked and your ad is visible.
You will see the following log if show was tracked successfully.
[Appodeal *.*.*] [debug] [impression] Impression <APDImpression: 0x600002953b10> succesfully tracked