Rewarded video ads aggregate rewarded video ads from other third-party ad platforms. You can use the ATRewardedVideo API to load and display ads. Two integration modes are currently supported, as described below:
| Mode (Choose One) | Description |
|---|---|
| Manual Request Mode | You call the ad load API yourself at the appropriate timing. See the integration suggestions below for details. |
| Auto Load Mode | A one-stop request maintenance solution launched by Taku that automatically determines the preloading and caching timing for the next ad based on user usage status and ad consumption progress, achieving better loading results. See: Rewarded Video Ad Auto Load Mode for details. |
ATRewardedVideo:
| API | Parameters | Description |
|---|---|---|
| loadVideoAd | string placementid, Dictionary | Load an ad |
| setListener | ATRewardedVideoListener listener | Set the listener callback interface. (Deprecated after version 5.9.51) For how to set listeners, see: Rewarded Video Ad Event Settings |
| hasAdReady | string placementid | Check if there is a cached ad |
| checkAdStatus | string placementid | (Added in v5.7.03) Get the current ad placement status (JSON string): 1. isLoading: Whether it is loading 2. isReady: Whether there is a cached ad (same as hasAdReady) 3. AdInfo: The highest-priority cached ad info (see ATCallbackInfo Description) |
| getValidAdCaches | string placementid | (Added in v5.7.54) Get all successfully loaded cached ad info (JSON string) (see ATCallbackInfo Description) |
| showAd | string placementid | Display an ad |
| showAd | string placementid, Dictionary | Use the scenario feature to display an ad |
| entryScenarioWithPlacementID | string placementid, string scenarioID | Set entry into a displayable ad scenario |
Use the following code to load a rewarded video ad:
public void loadVideo()
{
ATRewardedVideo.Instance.client.onAdLoadEvent += onAdLoad;
ATRewardedVideo.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
ATRewardedVideo.Instance.client.onAdVideoStartEvent += onAdVideoStartEvent;
ATRewardedVideo.Instance.client.onAdVideoEndEvent += onAdVideoEndEvent;
ATRewardedVideo.Instance.client.onAdVideoFailureEvent += onAdVideoPlayFail;
ATRewardedVideo.Instance.client.onAdClickEvent += onAdClick;
ATRewardedVideo.Instance.client.onRewardEvent += onReward;
ATRewardedVideo.Instance.client.onAdVideoCloseEvent += onAdVideoClosedEvent;
Dictionary jsonmap = new Dictionary();
//If you need to distribute rewards through the developer's server (some ad platforms support this server-side reward), you need to pass the following two keys
//ATConst.USERID_KEY is required and used to identify each user; ATConst.USER_EXTRA_DATA is optional and will be passed through to the developer's server
jsonmap.Add(ATConst.USERID_KEY, "test_user_id");
jsonmap.Add(ATConst.USER_EXTRA_DATA, "test_user_extra_data");
ATRewardedVideo.Instance.loadVideoAd(mPlacementId_rewardvideo_all,jsonmap);
}
Note: See below for how to get notified about rewarded video ad events (load success/failure, impression, click, video start/end, and reward).
ATRewardedVideo.Instance.hasAdReady(mPlacementId_rewardvideo_all);
Compared to displaying native ads, displaying rewarded video ads is much simpler. Just call the show API and pass the ad placement ID as a parameter:
public void showVideo()
{
Debug.Log ("Developer show video....");
ATRewardedVideo.Instance.showAd(mPlacementId_rewardvideo_all);
}
When using the scenario feature:
public void showVideo()
{
Debug.Log ("Developer show video....");
Dictionary jsonmap = new Dictionary();
jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenarioID);
// Plugin 2.1.8 added pass-through custom parameters on display
jsonmap.Add(AnyThinkAds.Api.ATConst.ShowConfig.SHOW_CUSTOM_EXT, showCustomExt);
ATRewardedVideo.Instance.showAd(mPlacementId_rewardvideo_all, jsonmap);
}
For callback info details, see: Callback Info Description
Use the following code to implement multiple listeners:
// Ad loaded successfully
ATRewardedVideo.Instance.client.onAdLoadEvent += onAdLoad;
// Ad load failed
ATRewardedVideo.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
// Ad impression callback (can rely on this callback for impression statistics)
ATRewardedVideo.Instance.client.onAdVideoStartEvent += onAdVideoStartEvent;
// Ad playback ended
ATRewardedVideo.Instance.client.onAdVideoEndEvent += onAdVideoEndEvent;
// Video ad playback failed
ATRewardedVideo.Instance.client.onAdVideoFailureEvent += onAdVideoPlayFail;
// Ad clicked
ATRewardedVideo.Instance.client.onAdClickEvent += onAdClick;
// Ad reward callback (can rely on this listener to distribute in-game rewards)
ATRewardedVideo.Instance.client.onRewardEvent += onReward;
// Ad closed
ATRewardedVideo.Instance.client.onAdVideoCloseEvent += onAdVideoClosedEvent;
Advanced listener settings:
// Ad Source initiated request
ATRewardedVideo.Instance.client.onAdSourceAttemptEvent += startLoadingADSource;
// Ad Source loaded successfully
ATRewardedVideo.Instance.client.onAdSourceFilledEvent += finishLoadingADSource;
// Ad Source load failed
ATRewardedVideo.Instance.client.onAdSourceLoadFailureEvent += failToLoadADSource;
// Ad Source Bidding started
ATRewardedVideo.Instance.client.onAdSourceBiddingAttemptEvent += startBiddingADSource;
// Ad Source Bidding succeeded
ATRewardedVideo.Instance.client.onAdSourceBiddingFilledEvent += finishBiddingADSource;
// Ad Source Bidding failed
ATRewardedVideo.Instance.client.onAdSourceBiddingFailureEvent += failBiddingADSource;
The method definition parameters are as follows (Note: You can refer to the code below for method names or use custom method names, but the parameters must be consistent):
// Ad loaded successfully
public void onAdLoad(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onAdLoad :" + erg.placementId);
}
// Ad load failed
public void onAdLoadFail(object sender,ATAdErrorEventArgs erg )
{
Debug.Log("Developer callback onAdLoadFail :" + erg.placementId + "--erg.code:" + code + "--msg:" + erg.message);
}
public void onAdVideoStartEvent(object sender, ATAdEventArgs erg) {
Debug.Log("Developer onAdVideoStartEvent------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
}
public void onAdVideoEndEvent(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdVideoEndEvent------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
}
public void onAdVideoPlayFail(object sender, ATAdErrorEventArgs erg)
{
Debug.Log("Developer onAdVideoClosedEvent------" + "->" + JsonMapper.ToJson(erg.errorMessage));
}
//sender is the ad type object, erg is the returned info
// Ad clicked
public void onAdClick(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onAdClick :" + erg.placementId);
}
public void onReward(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onReward------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
}
public void onAdVideoClosedEvent(object sender, ATAdEventArgs erg)
{
Debug.Log("Developer onAdVideoClosedEvent------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
}
public void startLoadingADSource(object sender,ATAdEventArgs erg){
Debug.Log("Developer startLoadingADSource------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toAdsourceDictionary()));
}
public void finishLoadingADSource(object sender,ATAdEventArgs erg){
Debug.Log("Developer finishLoadingADSource------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toAdsourceDictionary()));
}
public void failToLoadADSource(object sender,ATAdErrorEventArgs erg ){
Debug.Log("Developer failToLoadADSource------erg.errorCode:" + erg.errorCode + "---erg.errorMessage:" + erg.errorMessage+ "->" + JsonMapper.ToJson(erg.callbackInfo.toAdsourceDictionary()));
}
public void startBiddingADSource(object sender,ATAdEventArgs erg){
Debug.Log("Developer startBiddingADSource------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toAdsourceDictionary()));
}
public void finishBiddingADSource(object sender,ATAdEventArgs erg){
Debug.Log("Developer finishBiddingADSource------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toAdsourceDictionary()));
}
public void failBiddingADSource(object sender,ATAdErrorEventArgs erg ){
Debug.Log("Developer failBiddingADSource------erg.errorCode:" + erg.errorCode + "---erg.errorMessage:" + erg.errorMessage+ "->" + JsonMapper.ToJson(erg.callbackInfo.toAdsourceDictionary()));
}
Watch Another Ad: Only Pangle supports the Watch Another Ad callback
// Rewarded video watch another ad - video playback started
ATRewardedVideo.Instance.client.onPlayAgainStart += onRewardedVideoAdAgainPlayStart;
// Rewarded video watch another ad - video playback failed
ATRewardedVideo.Instance.client.onPlayAgainFailure += onRewardedVideoAdAgainPlayFail;
// Rewarded video watch another ad - video playback ended
ATRewardedVideo.Instance.client.onPlayAgainEnd += onRewardedVideoAdAgainPlayEnd;
// Rewarded video watch another ad - video clicked
ATRewardedVideo.Instance.client.onPlayAgainClick += onRewardedVideoAdAgainPlayClicked;
// Rewarded video watch another ad - reward granted
ATRewardedVideo.Instance.client.onPlayAgainReward += onAgainReward;
public void onRewardedVideoAdAgainPlayStart(object sender,ATAdEventArgs erg){
Debug.Log("Developer onRewardedVideoAdAgainPlayStart------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
}
public void onRewardedVideoAdAgainPlayEnd(object sender,ATAdEventArgs erg){
Debug.Log("Developer onRewardedVideoAdAgainPlayEnd------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
}
public void onRewardedVideoAdAgainPlayFail(object sender,ATAdErrorEventArgs erg){
Debug.Log("Developer onRewardedVideoAdAgainPlayFail------code:" + erg.errorCode + "---message:" + erg.errorMessage);
}
public void onRewardedVideoAdAgainPlayClicked(object sender,ATAdEventArgs erg){
Debug.Log("Developer onRewardedVideoAdAgainPlayClicked------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
}
public void onAgainReward(object sender, ATAdEventArgs erg){
Debug.Log("Developer onAgainReward------" + "->" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
}
You can implement a class that implements the ATRewardedVideo Listener interface to get notified about rewarded video ad events, xxxxx: (Note: For Android, all callback methods are not on the Unity main thread)
class ATCallbackListener : ATRewardedVideoListener {
// Ad loaded successfully
public void onRewardedVideoAdLoaded(string placementId){
Debug.Log("Developer onRewardedVideoAdLoaded------");
}
// Ad load failed
public void onRewardedVideoAdLoadFail(string placementId, string code, string message){
Debug.Log("Developer onRewardedVideoAdLoadFail------:code" + code + "--message:" + message);
}
// Ad playback started
public void onRewardedVideoAdPlayStart(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer onRewardedVideoAdPlayStart------");
}
// Ad playback ended
public void onRewardedVideoAdPlayEnd(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer onRewardedVideoAdPlayEnd------");
}
// Ad playback failed
public void onRewardedVideoAdPlayFail(string placementId, string code, string message){
Debug.Log("Developer onRewardedVideoAdPlayFail------code:" + code + "---message:" + message);
}
// Ad closed, where isReward only indicates whether the onReward() method was called back when onRewardedVideoAdPlayClosed was called back
public void onRewardedVideoAdPlayClosed(string placementId, bool isReward, ATCallbackInfo callbackInfo){
Debug.Log("Developer onRewardedVideoAdPlayClosed------isReward:" + isReward);
}
// Ad clicked
public void onRewardedVideoAdPlayClicked(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer onRewardVideoAdPlayClicked------");
}
// Reward granted. Developers can distribute rewards in this callback. It generally precedes the onRewardedVideoAdPlayClosed callback, but this is not guaranteed for server-side rewards
public void onReward(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer onReward------");
}
// v5.8.10 added Ad Source-level callbacks
// Ad Source started loading
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer startLoadingADSource------");
}
// Ad Source loading completed
public void finishLoadingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer finishLoadingADSource------");
}
// Ad Source failed
public void failToLoadADSource(string placementId,ATCallbackInfo callbackInfo,string code, string message){
Debug.Log("Developer failToLoadADSource------");
}
// Ad Source started bidding
public void startBiddingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer startBiddingADSource------");
}
// Ad Source bidding succeeded
public void finishBiddingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer finishBiddingADSource------");
}
// Ad Source bidding failed
public void failBiddingADSource(string placementId,ATCallbackInfo callbackInfo,string code, string message){
Debug.Log("Developer failBiddingADSource------");
}
}
Create an instance of this class and pass it to the listener parameter in the load API, see here
Note: V5.7.82 and above, only Pangle supports the Watch Another Ad callback
class ATCallbackListener : ATRewardedVideoExListener {
// Rewarded video watch another ad - video playback started
public void onRewardedVideoAdAgainPlayStart(string placementId, ATCallbackInfo callbackInfo) {
Debug.Log("Developer onRewardedVideoAdAgainPlayStart------");
}
// Rewarded video watch another ad - video playback ended
public void onRewardedVideoAdAgainPlayEnd(string placementId, ATCallbackInfo callbackInfo) {
Debug.Log("Developer onRewardedVideoAdAgainPlayEnd------");
}
// Rewarded video watch another ad - video playback failed
public void onRewardedVideoAdAgainPlayFail(string placementId, string code, string message) {
Debug.Log("Developer onRewardedVideoAdAgainPlayFail------");
}
// Rewarded video watch another ad - video clicked
public void onRewardedVideoAdAgainPlayClicked(string placementId, ATCallbackInfo callbackInfo) {
Debug.Log("Developer onRewardedVideoAdAgainPlayClicked------");
}
// Rewarded video watch another ad - reward granted
public void onAgainReward(string placementId, ATCallbackInfo callbackInfo) {
Debug.Log("Developer onAgainReward------");
}
}
Note: The code snippets in this section are from the videoScenes.cs demo project in our Demo.