Menu

Fully automatic loading of interstitial ads


The fully automatic loading mode is a one-stop request maintenance solution launched by TopOn. It can intelligently determine the preloading and caching timing of the next advertisement based on the user's usage status and ad consumption progress with multiple nodes. On the basis of satisfying the developer's operation strategy, it avoids the risk of failure in real-time loading of advertising data and wasted display opportunities, and alleviates users' negative emotions caused by ads not loading or loading not smoothly. Through fully automatic loading of solutions, developers can avoid repeated and cumbersome manual intervention request solutions, and efficiency improvements are immediate.

1. Access process suggestions

  1. Load ads by calling ATInterstitialAutoAd#addAutoLoadAdPlacementID when starting the application
  2. Use ATInterstitialAutoAd#autoLoadInterstitialAdReadyForPlacementID to determine whether it can be displayed where the advertisement needs to be displayed
  3. If you need to use Advertising scenariosDistinguish the data of different business scenarios, please refer to the sample code for details

Note: If the advertising space is set to fully automatic loading, Don't call ATInterstitialAd#loadInterstitialAd (Normal interstitial ad) for advertising Loading

2. API Description

ATInterstitialAutoAd:

APIParametersDescription
addAutoLoadAdPlacementIDstring[] placementIDListSet ad slots that need to be loaded automatically
removeAutoLoadAdPlacementIDstring placementIdRemove ad slots that do not require automatic loading
setAutoLocalExtrastring placementId, string mapJsonSet additional parameters for the ad slot
setListenerATRewardedVideoListener listener (Abandoned after version 5.9.51) For details on how to set up a listener, please refer to: Insert screen Ad event setting instructions**
autoLoadInterstitialAdReadyForPlacementIDstring placementidDetermine whether there is an ad cache
checkAdStatusstring placementid
getAutoValidAdCachesstring placementid(new in v5.7.54)Get successfully loaded All ad cache information (JSON string)
(refer to ATCallbackInfo description)
showAutoAdstring mapJsonshow ads
showAutoAdstring placementid, Dictionary<string,string> extraUse scene function to display ads more
entryAutoAdScenarioWithPlacementIDstring placementid, string scenarioIDSet to enter the displayable advertising scenario

3. Set local parameters

4. Load ads

Use the following code to set up fully automatic loading of interstitial ads:

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

5. Determine whether there is advertising cache

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

6. Display ads

public void showAutoAd()
{
    ATInterstitialAutoAd.Instance.showAutoAd(mPlacementId_interstitial_all);
}

When using the Scene function:

public void showAutoAd()
{
        //Set up the scene
    ATInterstitialAutoAd.Instance.entryAutoAdScenarioWithPlacementID(mPlacementId_interstitial_all, showingScenario);
    Dictionary<string, string> jsonmap = new Dictionary<string, string>();
    jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenario);
    ATInterstitialAutoAd.Instance.showAutoAd(mPlacementId_interstitial_all,jsonmap);
}

7. Implement fully automatic loading of multiple listeners for interstitial ads (note: only supported in V5.9.51 and above)

Please see the callback information details: Callback information description

Use the following code to implement multiple listeners

        //Advertisement loaded successfully
        ATRewardedAutoVideo.Instance.client.onAdLoadEvent += onAdLoad; 
        //Ad loading failed
        ATRewardedAutoVideo.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
        //Ad display callback (you can rely on this callback to count display data)
        ATRewardedAutoVideo.Instance.client.onAdVideoStartEvent  += onAdVideoStartEvent;
        //Advertisement ends
        ATRewardedAutoVideo.Instance.client.onAdVideoEndEvent  += onAdVideoEndEvent;
        //Advertisement video playback failed
        ATRewardedAutoVideo.Instance.client.onAdVideoFailureEvent += onAdVideoPlayFail;
        //ad click
        ATRewardedAutoVideo.Instance.client.onAdClickEvent += onAdClick;
        //Advertising incentive callback (you can rely on this listener to issue game incentives)
        ATRewardedAutoVideo.Instance.client.onRewardEvent += onReward;
        //广告被关闭
        ATRewardedAutoVideo.Instance.client.onAdVideoCloseEvent += onAdVideoClosedEvent;

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)

    //sender is the advertising type object, erg is the return information
    //Advertisement loaded successfully
    public void onAdLoad(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdLoad :" + erg.placementId);
    }

    //Ad loading failed
    public void onAdLoadFail(object sender,ATAdErrorEventArgs erg )
    {
        Debug.Log("Developer callback onInterstitialAdLoadFail :" + erg.placementId + "--erg.code:" + code + "--msg:" + erg.message);
    }

    //Advertisement displayed successfully
    public void onShow(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdShow :" +erg. placementId);
    }

    //ad clicked
    public void onAdClick(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdClick :" + erg.placementId);
    }

    //Ads are turned off
    public void onAdClose(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdClose :" + erg.placementId);
    }

    //The advertising video starts playing. Some platforms have this callback.
​
    public void startVideoPlayback(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdStartPlayingVideo :" + erg.placementId);
    }

    //The advertising video ends. Some advertising platforms have this callback.
    public void endVideoPlayback(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdEndPlayingVideo :" + erg.placementId);
    }

    //Ad video playback failed, some advertising platforms have this callback
    public void failVideoPlayback(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdFailedToPlayVideo :" + erg.placementId + "--code:" + erg.code + "--msg:" + erg.message);
    }


8. The old version implements fully automatic loading of interstitial advertising listeners (note: only in Used below V5.9.51, new versions are obsolete)

You can implement ATRewardedAutoVideo Listener interface class to get notifications about rewarded video advertising events: (Note: For Android, all callback methods are not in Unity's main thread)

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

Note:  The code snippets in this section are excerpted from our Demo's interstitialScenes Demo project.

Previous
Interstitial ad
Next
Banner Ad
Last modified: 2025-05-30Powered by