The Rewarded Video ad aggregates rewarded video ads from other third-party ad networks. You can use the ATRewardedVideo API to load and display ads. Currently, two integration methods are supported, as described below:
| Mode (choose one) | Description |
|---|---|
| Manual Request Mode | You call ad loading through the API at an appropriate time at your own discretion. Refer to the integration suggestions below in the document for details. |
| Auto Load Mode | A one-stop request management solution launched by TopOn, which can automatically determine the preloading and caching timing of the next ad based on the user's usage status and ad consumption progress, achieving better loading performance. 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) |
| hasAdReady | string placementid | Check if there is an ad cache |
| showAd | string placementid | Show an ad |
| showAd | string placementid, Dictionary | Show an ad using the scenario feature |
| 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 grant rewards through your own server (some ad networks support this server-side reward), you need to pass the following two keys
// ATConst.USERID_KEY is required, used to identify each user; ATConst.USER_EXTRA_DATA is an optional parameter, and once passed, it will be forwarded to your 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: Please refer to the following section to learn how to receive notifications about rewarded video ad events (load success/failure, display, click, video start/end, and reward).
ATRewardedVideo.Instance.hasAdReady(mPlacementId_rewardvideo_all);
Compared to displaying native ads, displaying a rewarded video ad is much simpler. Just call the show API and pass the 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);
// Added in plugin version 2.1.8: pass custom parameters during display
jsonmap.Add(AnyThinkAds.Api.ATConst.ShowConfig.SHOW_CUSTOM_EXT, showCustomExt);
ATRewardedVideo.Instance.showAd(mPlacementId_rewardvideo_all, jsonmap);
}
For callback information details, please see: Callback Information Description
Use the following code to implement multiple listeners:
// Ad loading succeeded
ATRewardedVideo.Instance.client.onAdLoadEvent += onAdLoad;
// Ad loading failed
ATRewardedVideo.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
// Ad display callback (this callback can be relied on for impression statistics)
ATRewardedVideo.Instance.client.onAdVideoStartEvent += onAdVideoStartEvent;
// Ad playback ended
ATRewardedVideo.Instance.client.onAdVideoEndEvent += onAdVideoEndEvent;
// Ad video playback failed
ATRewardedVideo.Instance.client.onAdVideoFailureEvent += onAdVideoPlayFail;
// Ad clicked
ATRewardedVideo.Instance.client.onAdClickEvent += onAdClick;
// Ad reward callback (this listener can be relied on to grant in-game rewards)
ATRewardedVideo.Instance.client.onRewardEvent += onReward;
// Ad dismissed
ATRewardedVideo.Instance.client.onAdVideoCloseEvent += onAdVideoClosedEvent;
The method parameter definitions are as follows in the code (Note: The method name can follow the code below or be a custom method name, but the parameters must be consistent.):
// Ad loading succeeded
public void onAdLoad(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onAdLoad :" + erg.placementId);
}
// Ad loading 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 information
// 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()));
}