The Auto Load mode is a one-stop request management solution launched by TopOn, which can intelligently determine the preloading and caching timing of the next ad based on the user's usage status and ad consumption progress at multiple nodes. On the basis of meeting the developer's operational strategy, it avoids the risk of real-time ad loading failures and wasted impression opportunities, reducing negative user sentiment caused by ads not being loaded or loading not being smooth. With the Auto Load solution, developers can avoid repetitive and cumbersome manual intervention in request schemes, with immediate and noticeable efficiency improvements.
Note: If a placement is set to Auto Load, you must not call ATRewardedVideo#loadVideoAd (regular rewarded video) to load ads.
ATRewardedAutoVideo:
| API | Parameters | Description |
|---|---|---|
| addAutoLoadAdPlacementID | string\[\] placementIDList | Set the placements that need to be auto-loaded |
| removeAutoLoadAdPlacementID | string placementId | Remove the placements that do not need to be auto-loaded |
| setAutoLocalExtra | string placementId, string mapJson | Set local parameters for the placement |
| setListener | ATRewardedVideoListener listener | (Deprecated after version 5.9.51) For how to set the listener, refer to: Rewarded Video Ad Event Setup Instructions |
| autoLoadRewardedVideoReadyForPlacementID | string placementid | Check if there is an ad cache |
| showAutoAd | string mapJson | Show an ad |
| showAutoAd | string placementid, Dictionary extra | Show an ad using the scenario feature |
| entryAutoAdScenarioWithPlacementID | string placementid, string scenarioID | Set entry into a displayable ad scenario |
If you need to support server-side reward callbacks, you need to pass the parameters before configuring the auto load placement (effective for the next rewarded video ad load). Sample code:
public void setAutoLoadExtra()
{
Dictionary<string> jsonmap = new Dictionary<string>();
// 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");
ATRewardedAutoVideo.Instance.setAutoLocalExtra(mPlacementId_rewardvideo_all, jsonmap);
}</string></string>
Use the following code to set up Auto Load for rewarded video ads:
public void addAutoLoadAdPlacementID()
{
ATRewardedAutoVideo.Instance.client.onAdLoadEvent += onAdLoad;
ATRewardedAutoVideo.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
ATRewardedAutoVideo.Instance.client.onAdVideoStartEvent += onAdVideoStartEvent;
ATRewardedAutoVideo.Instance.client.onAdVideoEndEvent += onAdVideoEndEvent;
ATRewardedAutoVideo.Instance.client.onAdVideoFailureEvent += onAdVideoPlayFail;
ATRewardedAutoVideo.Instance.client.onAdClickEvent += onAdClick;
ATRewardedAutoVideo.Instance.client.onRewardEvent += onReward;
ATRewardedAutoVideo.Instance.client.onAdVideoCloseEvent += onAdVideoClosedEvent;
string[] jsonList = {mPlacementId_rewardvideo_all};
ATRewardedAutoVideo.Instance.addAutoLoadAdPlacementID(jsonList);
}
Note: Please refer to the following section to learn how to receive notifications about Auto Load rewarded video ad events (load success/failure, display, click, video start/end, and reward).
bool isReady = ATRewardedAutoVideo.Instance.autoLoadRewardedVideoReadyForPlacementID(mPlacementId_rewardvideo_all);
public void showAutoAd()
{
ATRewardedAutoVideo.Instance.showAutoAd(mPlacementId_rewardvideo_all);
}
When using the scenario feature:
public void showAutoAd()
{
// Set entry into scenario
ATRewardedAutoVideo.Instance.entryAutoAdScenarioWithPlacementID(mPlacementId_rewardvideo_all, showingScenario);
Dictionary<string string=""> jsonmap = new Dictionary<string string="">();
jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenario);
ATRewardedAutoVideo.Instance.showAutoAd(mPlacementId_rewardvideo_all,jsonmap);
}</string></string>
For callback information details, please see: Callback Information Description
Use the following method to support setting multiple listeners:
// Ad loading succeeded
ATRewardedAutoVideo.Instance.client.onAdLoadEvent += onAdLoad;
// Ad loading failed
ATRewardedAutoVideo.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
// Ad display callback (this callback can be relied on for impression statistics)
ATRewardedAutoVideo.Instance.client.onAdVideoStartEvent += onAdVideoStartEvent;
// Ad playback ended
ATRewardedAutoVideo.Instance.client.onAdVideoEndEvent += onAdVideoEndEvent;
// Ad video playback failed
ATRewardedAutoVideo.Instance.client.onAdVideoFailureEvent += onAdVideoPlayFail;
// Ad clicked
ATRewardedAutoVideo.Instance.client.onAdClickEvent += onAdClick;
// Ad reward callback (this listener can be relied on to grant in-game rewards)
ATRewardedAutoVideo.Instance.client.onRewardEvent += onReward;
// Ad dismissed
ATRewardedAutoVideo.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()));
}