Rewarded video ads are rewarded video ads that aggregate other third-party advertising platforms. You can use ATRewardedVideo's API to load and play ads. Currently, two integration methods are supported, the details are as follows:
Mode (choose one) | Description |
---|---|
Manual request mode | You choose the appropriate time to load the ad through the API , please refer to the integration suggestions below the document for details |
Fully automatic loading mode | TopOn's one-stop request maintenance solution can automatically determine the preloading and caching timing of the next advertisement based on the user's usage status and ad consumption progress to achieve better results. Loading effect, see for details: Fully automatic loading mode for rewarded video ads |
ATRewardedVideo:
API | Parameters | Description |
---|---|---|
loadVideoAd | string placementid, Dictionary<string,string> extra | |
setListener< /td> | ATRewardedVideoListener listener | Set the listening callback interface(Abandoned after version 5.9.51) For details on how to set the listener, please refer to: Rewarded video ad event setting instructions |
hasAdReady | string placementid | Determine whether there is Ad cache |
checkAdStatus | string placementid | ( New in v5.7.03)Get the status of the current ad slot (Json string): 1. isLoading: whether it is loading 2. isReady: whether there is an ad cache (with hasAdReady The function is the same) 3. AdInfo: the current highest priority advertising cache information (refer to ATCallbackInfo description) |
getValidAdCaches | string placementid< /td> | (new in v5.7.54)Get all successfully loaded ad cache information (JSON string) (refer to ATCallbackInfo description) |
showAd | string placementid | Display ads |
showAd | string placementid,Dictionary<string,string> extra | Use the scene function to display ads more |
entryScenarioWithPlacementID | string placementid, string scenarioID | Settings can be entered Display advertising scene |
Use the following code to load rewarded video ads:
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<string,string> jsonmap = new Dictionary<string,string>();
//If you need to distribute rewards through the developer's server (some advertising platforms support this server incentive), you need to pass the following two keys
//ATConst.USERID_KEY must be passed, used to identify each user; ATConst.USER_EXTRA_DATA is an optional parameter, which will be transparently transmitted to the developer's server after being passed in.
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 to learn how Get notified on rewarded video ad events (load success/failure, impression, click, video start/end and reward).
ATRewardedVideo.Instance.hasAdReady(mPlacementId_rewardvideo_all);
Compared with displaying native ads, displaying rewarded videos is much simpler. Just call the display api and pass Display ad slot ID as parameter:
public void showVideo()
{
Debug.Log ("Developer show video....");
ATRewardedVideo.Instance.showAd(mPlacementId_rewardvideo_all);
}
When used Scene Function:
public void showVideo()
{
Debug.Log ("Developer show video....");
Dictionary<string, string> jsonmap = new Dictionary<string, string>();
jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenarioID);
ATRewardedVideo.Instance.showAd(mPlacementId_rewardvideo_all, jsonmap);
}
For details of callback information, please see: Callback information description
Use the following code to implement multiple listeners
//ad load successfully
ATRewardedVideo.Instance.client.onAdLoadEvent += onAdLoad;
//Ad loading failed
ATRewardedVideo.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
//Ad display callback (you can rely on this callback to count display data)
ATRewardedVideo.Instance.client.onAdVideoStartEvent += onAdVideoStartEvent;
//Advertisement ends
ATRewardedVideo.Instance.client.onAdVideoEndEvent += onAdVideoEndEvent;
//Advertisement video playback failed
ATRewardedVideo.Instance.client.onAdVideoFailureEvent += onAdVideoPlayFail;
//ad click
ATRewardedVideo.Instance.client.onAdClickEvent += onAdClick;
//Advertising incentive callback (you can rely on this listener to issue game incentives)
ATRewardedVideo.Instance.client.onRewardEvent += onReward;
//Ads are turned off
ATRewardedVideo.Instance.client.onAdVideoCloseEvent += onAdVideoClosedEvent;
Advanced listening Settings:
//Ad source activation request
ATRewardedVideo.Instance.client.onAdSourceAttemptEvent += startLoadingADSource;
//Advertising source loaded successfully
ATRewardedVideo.Instance.client.onAdSourceFilledEvent += finishLoadingADSource;
//Ad source loading failed
ATRewardedVideo.Instance.client.onAdSourceLoadFailureEvent += failToLoadADSource;
//Advertising source Bidding started
ATRewardedVideo.Instance.client.onAdSourceBiddingAttemptEvent += startBiddingADSource;
//Advertising source Bidding successful
ATRewardedVideo.Instance.client.onAdSourceBiddingFilledEvent += finishBiddingADSource;
//Advertising source Bidding failed
ATRewardedVideo.Instance.client.onAdSourceBiddingFailureEvent += failBiddingADSource;
The method definition parameters are as follows (Note: The method name can refer to the following code or customize the method name, but the parameters must be consistent)
Look at another callback: only supported by Pangolin Look at another callback
// RewardedVideo watch again video starts playing
ATRewardedVideo.Instance.client.onPlayAgainStart += onRewardedVideoAdAgainPlayStart;
//RewardedVideo watch again video failed to play
ATRewardedVideo.Instance.client.onPlayAgainFailure += onRewardedVideoAdAgainPlayFail;
// RewardedVideo watch again video playback ends
ATRewardedVideo.Instance.client.onPlayAgainEnd += onRewardedVideoAdAgainPlayEnd;
// RewardedVideo to watch the video again click
ATRewardedVideo.Instance.client.onPlayAgainClick += onRewardedVideoAdAgainPlayClicked;
// RewardedVideo Watch the video again to encourage sending
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 the ATRewardedVideo Listener interface class to get notifications about rewarded video advertising events, xxxxx: (Note: For Android, all callback methods are not on the main thread of Unity)
class ATCallbackListener : ATRewardedVideoListener {
//Advertisement loaded successfully
public void onRewardedVideoAdLoaded(string placementId){
Debug.Log("Developer onRewardedVideoAdLoaded------");
}
//Ad loading failed
public void onRewardedVideoAdLoadFail(string placementId, string code, string message){
Debug.Log("Developer onRewardedVideoAdLoadFail------:code" + code + "--message:" + message);
}
//ad starts playing
public void onRewardedVideoAdPlayStart(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer onRewardedVideoAdPlayStart------");
}
//Advertisement ends
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);
}
//The advertisement is 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------");
}
//If the incentive is successful, the developer can issue the reward in this callback, usually before the onRewardedVideoAdPlayClosed callback, but not necessarily for server incentives.
public void onReward(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer onReward------");
}
//v5.8.10 adds ad source level callbacks
// Advertising source starts loading
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer startLoadingADSource------");
}
//Advertising 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------");
}
// Advertising sources start bidding
public void startBiddingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer startBiddingADSource------");
}
//Advertising source bidding successful
public void finishBiddingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer finishBiddingADSource------");
}
// Advertising 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 loading api,Reference here
Note: V5.7.82 and above only support Pangolin to watch another callback.
class ATCallbackListener : ATRewardedVideoExListener {
//Incentive video watch again video starts playing
public void onRewardedVideoAdAgainPlayStart(string placementId, ATCallbackInfo callbackInfo) {
Debug.Log("Developer onRewardedVideoAdAgainPlayStart------");
}
// Incentive video watch again video playback ends
public void onRewardedVideoAdAgainPlayEnd(string placementId, ATCallbackInfo callbackInfo) {
Debug.Log("Developer onRewardedVideoAdAgainPlayEnd------");
}
//Incentive video watch again video failed to play
public void onRewardedVideoAdAgainPlayFail(string placementId, string code, string message) {
Debug.Log("Developer onRewardedVideoAdAgainPlayFail------");
}
// Incentive video to watch the video again click
public void onRewardedVideoAdAgainPlayClicked(string placementId, ATCallbackInfo callbackInfo) {
Debug.Log("Developer onRewardedVideoAdAgainPlayClicked------");
}
// Incentive video: Watch the video again to encourage sending
public void onAgainReward(string placementId, ATCallbackInfo callbackInfo) {
Debug.Log("Developer onAgainReward------");
}
}
Note: The code snippets in this section are excerpted from our Demo’s videoScenes.cs demo project.