全自动加载模式,是Taku推出的一站式请求维护方案,能够根据用户的使用状态和广告消耗进度,多节点智能判断下一条广告的预加载和缓存时机。在满足开发者运营策略的基础上,规避广告数据实时加载的失败风险和展示机会被浪费,减轻用户因为广告未加载或加载不流畅造成的负面情绪。通过全自动加载方案,开发者可以避免反复冗杂的人工干预请求方案,效率提升立竿见影。
注:广告位如果设置为全自动加载则不要调用 ATInterstitialAd#loadInterstitialAd(普通插屏广告)进行广告加载
ATInterstitialAutoAd:
API | 参数 | 说明 |
---|---|---|
addAutoLoadAdPlacementID | string[] placementIDList | 设置需要自动加载的广告位 |
removeAutoLoadAdPlacementID | string placementId | 移除不需要自动加载的广告位 |
setListener | ATRewardedVideoListener listener | (5.9.51版本之后废弃)设置监听器的方式具体参考: 插屏广告事件设置说明** |
autoLoadInterstitialAdReadyForPlacementID | string placementid | 判断是否有广告缓存 |
checkAdStatus | string placementid | (v5.7.03新增)获取当前广告位的状态(Json字符串): 1、isLoading:是否正在加载 2、isReady:是否有广告缓存(与hasAdReady作用相同) 3、AdInfo:当前优先级最高的广告缓存信息(参考ATCallbackInfo说明) |
getAutoValidAdCaches | string placementid | (v5.7.54新增)获取加载成功的全部广告缓存信息(JSON字符串) (参考ATCallbackInfo说明) |
showAutoAd | string mapJson | 显示广告 |
showAutoAd | string placementid,Dictionary | 使用场景功能更显示广告 |
entryAutoAdScenarioWithPlacementID | string placementid,string scenarioID | 设置进入可展示广告场景 |
使用以下代码设置全自动加载插屏广告:
public void addAutoLoadAdPlacementID()
{
ATInterstitialAutoAd.Instance.client.onAdLoadEvent += onAdLoad;
ATInterstitialAutoAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
ATInterstitialAutoAd.Instance.client.onAdShowEvent += onShow;
ATInterstitialAutoAd.Instance.client.onAdClickEvent += onAdClick;
ATInterstitialAutoAd.Instance.client.onAdCloseEvent += onAdClose;
ATInterstitialAutoAd.Instance.client.onAdShowFailureEvent += onAdShowFail;
ATInterstitialAutoAd.Instance.client.onAdVideoStartEvent += startVideoPlayback;
ATInterstitialAutoAd.Instance.client.onAdVideoEndEvent += endVideoPlayback;
ATInterstitialAutoAd.Instance.client.onAdVideoFailureEvent += failVideoPlayback;
string[] jsonList = {mPlacementId_interstitial_all};
ATInterstitialAutoAd.Instance.addAutoLoadAdPlacementID(jsonList);
}
bool isReady = ATInterstitialAutoAd.Instance.autoLoadInterstitialAdReadyForPlacementID(mPlacementId_interstitial_all);
public void showAutoAd()
{
ATInterstitialAutoAd.Instance.showAutoAd(mPlacementId_interstitial_all);
}
当用到 场景 功能时:
public void showAutoAd()
{
// 设置进入场景
ATInterstitialAutoAd.Instance.entryAutoAdScenarioWithPlacementID(mPlacementId_interstitial_all, showingScenario);
Dictionary jsonmap = new Dictionary();
jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenario);
ATInterstitialAutoAd.Instance.showAutoAd(mPlacementId_interstitial_all,jsonmap);
}
回调信息详情请查看:回调信息说明
使用以下代码实现多个监听器
//广告加载成功
ATInterstitialAutoAd.Instance.client.onAdLoadEvent += onAdLoad;
//广告加载失败
ATInterstitialAutoAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
//广告展示(可以依赖该回调进行展示统计)
ATInterstitialAutoAd.Instance.client.onAdShowEvent += onShow;
//广告点击
ATInterstitialAutoAd.Instance.client.onAdClickEvent += onAdClick;
//广告关闭
ATInterstitialAutoAd.Instance.client.onAdCloseEvent += onAdClose;
//广告展示失败
ATInterstitialAutoAd.Instance.client.onAdShowFailureEvent += onAdShowFail;
//视频广告播放开始
ATInterstitialAutoAd.Instance.client.onAdVideoStartEvent += startVideoPlayback;
//视频广告播放结束
ATInterstitialAutoAd.Instance.client.onAdVideoEndEvent += endVideoPlayback;
//视频广告播放失败
ATInterstitialAutoAd.Instance.client.onAdVideoFailureEvent += failVideoPlayback;
方法定义参数如下代码(注意 : 方法名可参考以下代码或者自定义方法名,但参数必须一致)
//sender 为广告类型对象,erg为返回信息
//广告加载成功
public void onAdLoad(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onInterstitialAdLoad :" + erg.placementId);
}
//广告加载失败
public void onAdLoadFail(object sender,ATAdErrorEventArgs erg )
{
Debug.Log("Developer callback onInterstitialAdLoadFail :" + erg.placementId + "--erg.code:" + code + "--msg:" + erg.message);
}
//广告展示成功
public void onShow(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onInterstitialAdShow :" +erg. placementId);
}
//广告被点击
public void onAdClick(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onInterstitialAdClick :" + erg.placementId);
}
//广告被关闭
public void onAdClose(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onInterstitialAdClose :" + erg.placementId);
}
//广告视频开始播放,部分平台有此回调
public void startVideoPlayback(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onInterstitialAdStartPlayingVideo :" + erg.placementId);
}
//广告视频播放结束,部分广告平台有此回调
public void endVideoPlayback(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onInterstitialAdEndPlayingVideo :" + erg.placementId);
}
//广告视频播放失败,部分广告平台有此回调
public void failVideoPlayback(object sender,ATAdEventArgs erg)
{
Debug.Log("Developer callback onInterstitialAdFailedToPlayVideo :" + erg.placementId + "--code:" + erg.code + "--msg:" + erg.message);
}
您可以实现ATRewardedAutoVideo Listener接口的类,来获得有关激励视频广告事件的通知:(注意:对于Android来说,所有回调方法均不在Unity的主线程)
class InterstitalCallback : ATInterstitialAdListener
{
//广告被点击
public void onInterstitialAdClick(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onInterstitialAdClick :" + placementId);
}
//广告被关闭
public void onInterstitialAdClose(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onInterstitialAdClose :" + placementId);
}
//广告视频播放结束,部分广告平台有此回调
public void onInterstitialAdEndPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onInterstitialAdEndPlayingVideo :" + placementId);
}
//广告视频播放失败,部分广告平台有此回调
public void onInterstitialAdFailedToPlayVideo(string placementId, string code, string message)
{
Debug.Log("Developer callback onInterstitialAdFailedToPlayVideo :" + placementId + "--code:" + code + "--msg:" + message);
}
//广告加载成功
public void onInterstitialAdLoad(string placementId)
{
Debug.Log("Developer callback onInterstitialAdLoad :" + placementId);
}
//广告加载失败
public void onInterstitialAdLoadFail(string placementId, string code, string message)
{
Debug.Log("Developer callback onInterstitialAdLoadFail :" + placementId + "--code:" + code + "--msg:" + message);
}
//广告展示成功
public void onInterstitialAdShow(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onInterstitialAdShow :" + placementId);
}
//广告视频开始播放,部分平台有此回调
public void onInterstitialAdStartPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onInterstitialAdStartPlayingVideo :" + placementId);
}
//广告展示失败
public void onInterstitialAdFailedToShow(string placementId)
{
Debug.Log("Developer callback onInterstitialAdFailedToShow :" + placementId);
}
// v5.8.10 新增广告源层级回调
// 广告源开始加载
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer startLoadingADSource------");
}
// 广告源加载完成
public void finishLoadingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer finishLoadingADSource------");
}
// 广告源失败
public void failToLoadADSource(string placementId,ATCallbackInfo callbackInfo,string code, string message){
Debug.Log("Developer failToLoadADSource------");
}
// 广告源开始bidding
public void startBiddingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer startBiddingADSource------");
}
// 广告源bidding成功
public void finishBiddingADSource(string placementId, ATCallbackInfo callbackInfo){
Debug.Log("Developer finishBiddingADSource------");
}
// 广告源bidding失败
public void failBiddingADSource(string placementId,ATCallbackInfo callbackInfo,string code, string message){
Debug.Log("Developer failBiddingADSource------");
}
}
注意: 本节中的代码段摘自我们Demo的interstitialScenes demo project.