Rewarded video

Rewarded video - user-initiated ads where users can earn in-app rewards in exchange for viewing a video ad.

Initialize Rewarded video

1. Import the namespaces:

using AppodealAds.Unity.Api;
using AppodealAds.Unity.Common;
2. Add the following code within the Start() method of your main scene’s MonoBehavior: 
Appodeal.initialize("YOUR_APPODEAL_APP_KEY", Appodeal.REWARDED_VIDEO, consentValue);

Initialization method requires 3 parameters:

  • appKey - appKey is generated when you add an application to Appodeal.
  • adType - Ad types can be combined using "|" operator. For example, Appodeal.INTERSTITIAL | Appodeal.REWARDED_VIDEO.
  • consentValue - is boolean, with 'false' meaning that the user declines to give the consent. Read our guide on collecting consent here.

By default, auto caching is enabled: Appodeal SDK starts to load rewarded video right away after the initialization method is called. The next rewarded video ad starts to load after the previous one was shown.

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 videos use the code below before the SDK initialization:

Appodeal.setAutoCache(Appodeal.REWARDED_VIDEO, false);
To cache rewarded video use:
Appodeal.cache(this, Appodeal.REWARDED_VIDEO);

Display rewarded video

To display interstitial, you need to call the following code in the activity:

Appodeal.show(Appodeal.REWARDED_VIDEO);

Check if a rewarded video is loaded

You can check status of loading before showing. This method return a boolean value indicating whether the rewarded video is loaded.

Appodeal.isLoaded(Appodeal.REWARDED_VIDEO);
We recommend you check caching it before trying to show. 

Example:

if(Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)) {
	Appodeal.show(this, Appodeal.REWARDED_VIDEO);	
}

Rewarded video placements

Appodeal SDK allows you to tag each impression with different placement. For using 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 like this in your activity:

Appodeal.show(this, 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:

if(Appodeal.canShow(Appodeal.REWARDED_VIDEO, “placementName”)){
	Appodeal.show(this,Appodeal.REWARDED_VIDEO, “placementName”);
}

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 and its settings will be applied.

Important!

Placement settings affect ONLY ad presentation, not loading or caching.


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. To implement them, you need to follow three steps:

1. Extend your class with IRewardedVideoAdListener:

YourClassName : IRewardedVideoAdListener;
2. Then call the following method:
Appodeal.setRewardedVideoCallbacks(this);
3. Now you can use the following callback methods within your  public class :
#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) 
{ 
	print("Video loaded"); 
} 

// Called when rewarded video failed to load
public void onRewardedVideoFailedToLoad() 
{ 
	print("Video failed"); 
} 

// Called when rewarded video was loaded, but cannot be shown (internal network errors, placement settings, or incorrect creative)
public void onRewardedVideoShowFailed() 
{ 
	print ("Video show failed"); 
} 

// Called when rewarded video is shown
public void onRewardedVideoShown() 
{ 
	print("Video shown"); 
} 

// Called when reward video is clicked
public void onRewardedVideoClicked()
{ 
	print("Video clicked"); 
} 

// Called when rewarded video is closed
public void onRewardedVideoClosed(bool finished) 
{ 
	print("Video closed"); 
}

// Called when rewarded video is viewed until the end
public void onRewardedVideoFinished(double amount, string name) 
{ 
	print("Reward: " + amount + " " + name); 
}

//Called when rewarded video is expired and can not be shown
public void onRewardedVideoExpired() 
{ 
	print("Video expired"); 
}
 
#endregion

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 .

Server-to-server (S2S) rewarded video callbacks

To secure you apps economy we offer S2S reward callbaks. To validate each reward you need to setup callback URL on your server that will receive reward information. We will pass user data to your callback URL that you will need to validate and adjust user balance accordingly.

1. Create reward callback URL on your server that will receive reward information.

2. Fill created URL and encryption key in the app settings in your dashboard.

3. Reward callback will be sent to your URL using GET request with two parameters:

{http://example.com/reward}?data1={data1}&data2={data2}
4. Your URL should decrypt the data and validate it.

5. Check impression_id for uniqueness and store it in your system to prevent duplicate transactions.

To set user ID use Appodeal.getUserSettings(this).setUserId("User#123") method before the SDK initialization.

We offer sample script 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 and we will provide it for 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 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.

Appodeal.getRewardParameters(placementName);

Get predicted eCPM

This method return expected eCPM for cached ad. Amount is calculated based on historical data for the current ad unit.

public static double getPredictedEcpm(Appodeal.REWARDED_VIDEO);

Mute rewarded video (Only for android platform)

You can mute video ads if calls is muted on the device. For muting you need to call the following code before the initialization method

Appodeal.muteVideosIfCallsMuted(true);