Menu

Interstitial ad

1. Introduction to interstitial advertising

Interstitial ads are an aggregation of image interstitial ads and video interstitial ads from other third-party advertising platforms. Both ad types can use the API of ATAdManager to load and play ads. Currently, two integration methods are supported, the details are as follows:

Mode (choose one)Description
Manual request modeYou choose the appropriate time to load the ad through the API , please refer to the integration suggestions below the document for details
Fully automatic loading modeTopOn's one-stop request maintenance solution can automatically determine the preloading and caching timing of the next advertisement based on the user's usage status and ad consumption progress to achieve better results. Loading effect, see for details: Fully automatic loading mode for interstitial ads
  1. Use ATInterstitialAd#loadInterstitialAd to load ads when starting the application
  2. Use ATInterstitialAd#hasInterstitialAdReady to determine whether the advertisement needs to be displayed where Can be displayed

false: Re-execute ATInterstitialAd#loadInterstitialAd to load ads

true: Execute ATInterstitialAd#showInterstitialAd to display the advertisement, and then execute ATInterstitialAd#loadInterstitialAd in the callback of onInterstitialAdClose to preload the next advertisement (loadInterstitialAd can be called directly in the callback of onInterstitialAdClose without going through the judgment of hasInterstitialAdReady, which helps to improve priority comparison. High display volume of advertising sources.)

3. Ad preloading:

Insert After the on-screen ad is displayed, there is no need to judge ATInterstitialAd#hasInterstitialAdReady in the callback of onInterstitialAdShow (v5.8.10 and later) or onInterstitialAdClose (less than v.5.8.10). Directly call ATInterstitialAd#loadInterstitialAd for preloading (which helps to improve the priority). The amount of impressions of the advertising source)

You can refer to Automatically request ads to turn on automatic request for ads (if preloading after display above has been implemented, there is no need to turn it on)

4. If you need to use advertising scenarios to distinguish data from different business scenarios, please refer to the sample code

3. API Description

ATInterstitialAd:

APIParametersDescription
loadInterstitialAdstring placementid, Dictionary<string,string> extraLoading ads
setListenerATInterstitialAdListener listenerSet listening Callback interface (Abandoned after version 5.9.51) For details on how to set the listener, please refer to: Interstitial ad event setting instructions
hasInterstitialAdReadystring placementid Determine whether there is ad cache
checkAdStatusstring placementid(new in v5.7.03)Get the status of the current advertising slot (Json string):
1. isLoading: whether it is loading
2. isReady: whether there is advertising cache (Same function as hasInterstitialAdReady)
3. AdInfo: the current highest priority ad cache information (refer to ATCallbackInfo description)
getValidAdCaches string placementid(new in v5.7.54 Added)Get all successfully loaded ad cache information (JSON string)
(refer to ATCallbackInfo description)
showInterstitialAdstring placementid,Dictionary<string,string> extraDisplay advertising
entryScenarioWithPlacementIDstring placementId, string scenarioIDSet to enter the displayable advertising scene

4. Load interstitial ads

Use the following Code to load interstitial ads

public void loadInterstitialAd() 
{

    ATInterstitialAd.Instance.client.onAdLoadEvent += onAdLoad; 
    ATInterstitialAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
    ATInterstitialAd.Instance.client.onAdShowEvent += onShow;
    ATInterstitialAd.Instance.client.onAdClickEvent += onAdClick;
    ATInterstitialAd.Instance.client.onAdCloseEvent += onAdClose;
    ATInterstitialAd.Instance.client.onAdShowFailureEvent += onAdShowFail;        
    ATInterstitialAd.Instance.client.onAdVideoStartEvent  += startVideoPlayback;
    ATInterstitialAd.Instance.client.onAdVideoEndEvent  += endVideoPlayback;
    ATInterstitialAd.Instance.client.onAdVideoFailureEvent  += failVideoPlayback;

    Dictionary<string,string> jsonmap = new Dictionary<string,string>();

    ATInterstitialAd.Instance.loadInterstitialAd(mPlacementId_interstitial_all, jsonmap);
}

Note: See below to learn how to get notified about interstitial ad events (load success/failure, impression, click, video start end).

5. Determine whether there is advertising cache

ATInterstitialAd.Instance.hasInterstitialAdReady(mPlacementId_interstitial_all);

6. Display interstitial ads

Same as rewarded videos, interstitial ads only need to call the display api and pass the display ad slot ID as a parameter :

public void showInterstitialAd() 
{
    ATInterstitialAd.Instance.showInterstitialAd(mPlacementId_interstitial_all);
}

When using Scene Function:

public void showInterstitialAd()
{
    Dictionary<string, string> jsonmap = new Dictionary<string, string>();
    jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenarioID);
    ATInterstitialAd.Instance.showInterstitialAd(mPlacementId_interstitial_all, jsonmap);
}        //Ad source activation request
        ATInterstitialAd.Instance.client.onAdSourceAttemptEvent += startLoadingADSource;
        //Advertising source loaded successfully
        ATInterstitialAd.Instance.client.onAdSourceFilledEvent += finishLoadingADSource;
        //Ad source loading failed
        ATInterstitialAd.Instance.client.onAdSourceLoadFailureEvent += failToLoadADSource;
        //Advertising source Bidding started
        ATInterstitialAd.Instance.client.onAdSourceBiddingAttemptEvent += startBiddingADSource;
        //Advertising source Bidding successful
        ATInterstitialAd.Instance.client.onAdSourceBiddingFilledEvent += finishBiddingADSource;
        //Advertising source Bidding failed
        ATInterstitialAd.Instance.client.onAdSourceBiddingFailureEvent += failBiddingADSource;

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
    //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 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);
    }
    //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);
    }
    //The advertising video starts playing. Some platforms have this callback.
    public void startVideoPlayback(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdStartPlayingVideo :" + erg.placementId);
    }
    //Ad display failed
    public void failVideoPlayback(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onInterstitialAdFailedToShow :" + erg.placementId);
    }

      // v5.8.10 adds ad source level callbacks
      // Advertising source starts loading
    public void startLoadingADSource(object sender,ATAdEventArgs erg){
        Debug.Log("Developer startLoadingADSource------");
    }
      // Advertising source loading completed
        public void finishLoadingADSource(object sender,ATAdEventArgs erg){
        Debug.Log("Developer finishLoadingADSource------");
    }
      // Ad source failed
        public void failToLoadADSource(object sender,ATAdEventArgs erg){
        Debug.Log("Developer failToLoadADSource------");
    }
      // Advertising sources start bidding
        public void startBiddingADSource(object sender,ATAdEventArgs erg){
               Debug.Log("Developer startBiddingADSource------");
    }
      // Advertising source bidding successful
        public void finishBiddingADSource(object sender,ATAdEventArgs erg){
        Debug.Log("Developer finishBiddingADSource------");
    }
      // Advertising source bidding failed
        public void failBiddingADSource(object sender,ATAdEventArgs erg){
        Debug.Log("Developer failBiddingADSource------");
    }          

8. The old version of the monitor that implements screen insertion (note: only used below version V5.9.51, the new version has been abandoned)

You You can implement a class that implements the ATInterstitialAdListener interface to get notifications about interstitial ad events: (Note: For Android, all callback methods are not in Unity’s main thread)

class InterstitalCallback : ATInterstitialAdListener
{
    //ad clicked
    public void onInterstitialAdClick(string placementId, ATCallbackInfo callbackInfo)
    {
        Debug.Log("Developer callback onInterstitialAdClick :" + placementId);
    }
    //Ads are turned off
    public void onInterstitialAdClose(string placementId, ATCallbackInfo callbackInfo)
    {
        Debug.Log("Developer callback onInterstitialAdClose :" + placementId);
    }
    //The advertising video ends. Some advertising platforms have this callback.
    public void onInterstitialAdEndPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
    {
        Debug.Log("Developer callback onInterstitialAdEndPlayingVideo :" + placementId);
    }
    //Ad video playback failed, some advertising platforms have this callback
​
    public void onInterstitialAdFailedToPlayVideo(string placementId, string code, string message)
    {
        Debug.Log("Developer callback onInterstitialAdFailedToPlayVideo :" + placementId + "--code:" + code + "--msg:" + message);
    }
    //Advertisement loaded successfully
    public void onInterstitialAdLoad(string placementId)
    {
        Debug.Log("Developer callback onInterstitialAdLoad :" + placementId);
    }
    //Ad loading failed
    public void onInterstitialAdLoadFail(string placementId, string code, string message)
    {
        Debug.Log("Developer callback onInterstitialAdLoadFail :" + placementId + "--code:" + code + "--msg:" + message);
    }
    //Advertisement displayed successfully
    public void onInterstitialAdShow(string placementId, ATCallbackInfo callbackInfo)
    {
        Debug.Log("Developer callback onInterstitialAdShow :" + placementId);
    }
    //The advertising video starts playing. Some platforms have this callback.
​
    public void onInterstitialAdStartPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
    {
        Debug.Log("Developer callback onInterstitialAdStartPlayingVideo :" + placementId);
    }
    //Ad display failed
    public void onInterstitialAdFailedToShow(string placementId)
    {
        Debug.Log("Developer callback onInterstitialAdFailedToShow :" + placementId);
    }

      //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 you see in this section are excerpted from our Demo's interstitialScenes. cs demo project.

Previous
Fully automatic loading of incentive videos
Next
Fully automatic loading of interstitial ads
Last modified: 2025-05-30Powered by