菜单

全自动加载插屏广告


全自动加载模式,是Taku推出的一站式请求维护方案,能够根据用户的使用状态和广告消耗进度,多节点智能判断下一条广告的预加载和缓存时机。在满足开发者运营策略的基础上,规避广告数据实时加载的失败风险和展示机会被浪费,减轻用户因为广告未加载或加载不流畅造成的负面情绪。通过全自动加载方案,开发者可以避免反复冗杂的人工干预请求方案,效率提升立竿见影。

1. 接入流程建议

  1. 启动应用时通过调用ATInterstitialAutoAd#addAutoLoadAdPlacementID来加载广告
  2. 在需要展示广告的位置通过ATInterstitialAutoAd#autoLoadInterstitialAdReadyForPlacementID判断是否能展示
  3. 如需使用广告场景区分不同业务场景的数据,具体参考示例代码

注:广告位如果设置为全自动加载则不要调用 ATInterstitialAd#loadInterstitialAd普通插屏广告)进行广告加载

2. API说明

ATInterstitialAutoAd:

API参数说明
addAutoLoadAdPlacementIDstring[] placementIDList设置需要自动加载的广告位
removeAutoLoadAdPlacementIDstring placementId移除不需要自动加载的广告位
setListenerATRewardedVideoListener listener (5.9.51版本之后废弃)设置监听器的方式具体参考: 插屏广告事件设置说明**
autoLoadInterstitialAdReadyForPlacementIDstring placementid判断是否有广告缓存
checkAdStatusstring placementid(v5.7.03新增)获取当前广告位的状态(Json字符串):
1、isLoading:是否正在加载
2、isReady:是否有广告缓存(与hasAdReady作用相同)
3、AdInfo:当前优先级最高的广告缓存信息(参考ATCallbackInfo说明
getAutoValidAdCachesstring placementid(v5.7.54新增)获取加载成功的全部广告缓存信息(JSON字符串)
(参考ATCallbackInfo说明
showAutoAdstring mapJson显示广告
showAutoAdstring placementid,Dictionary使用场景功能更显示广告
entryAutoAdScenarioWithPlacementIDstring placementid,string scenarioID设置进入可展示广告场景


3. 加载广告

使用以下代码设置全自动加载插屏广告:

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);
}

4. 判断是否有广告缓存

bool isReady = ATInterstitialAutoAd.Instance.autoLoadInterstitialAdReadyForPlacementID(mPlacementId_interstitial_all);

5. 展示广告

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);
}

6. 实现全自动加载插屏广告的多个监听器 (注意:仅在V5.9.51版本以上支持)

回调信息详情请查看回调信息说明

使用以下代码实现多个监听器

        //广告加载成功
        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);
    }


7. 旧版实现全自动加载插屏广告的监听器 (注意:仅在V5.9.51版本以下使用,新版本已废弃)

您可以实现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.


上一个
插屏广告集成说明
下一个
Banner广告集成说明
最近修改: 2025-05-30Powered by