Menu

Banner Ad

1. Integration Process Suggestions

  1. When the app starts, execute ad loading via ATBannerAd#loadBannerAd.
  2. When displaying the ad for the first time after a successful load, execute ATBannerAd#showBannerAd(string placementid, string position) to display the ad.
  3. If you need to hide the ad, execute ATBannerAd#hideBannerAd. If you need to redisplay it after hiding, execute ATBannerAd#showBannerAd(string placementid).
  4. You can configure the refresh time through the TopOn dashboard placement -> Advanced Settings to enable the auto-refresh feature.

2. API Description

ATBannerAd:

API Parameters Description
loadBannerAd string placementid, Dictionary extra Load an ad
setListener ATBannerAdListener listener Set the listener callback interface (deprecated after version 5.9.51)
showBannerAd string placementid, string position Show the ad for the first time. position: ATBannerAdLoadingExtra.kATBannerAdShowingPisitionTop (display at the top of the screen), ATBannerAdLoadingExtra.kATBannerAdShowingPisitionBottom (display at the bottom of the screen)
hideBannerAd string placementid Hide the ad
showBannerAd string placementid Show an ad that has been previously hidden
cleanBannerAd string placementid Remove the ad

Use the following code to load a Banner ad:

java Copy
public void loadBannerAd()
{
   ATBannerAd.Instance.client.onAdLoadEvent += onAdLoad;  
   ATBannerAd.Instance.client.onAdLoadFailureEvent +=onAdLoadFail;
   ATBannerAd.Instance.client.onAdImpressEvent += onAdImpress;
   ATBannerAd.Instance.client.onAdAutoRefreshEvent += onAdAutoRefresh;
   ATBannerAd.Instance.client.onAdAutoRefreshFailureEvent += onAdAutoRefreshFail;
   ATBannerAd.Instance.client.onAdClickEvent += onAdClick;
   ATBannerAd.Instance.client.onAdCloseEvent += onAdCloseButtonTapped;    

  Dictionary<string object=""> jsonmap = new Dictionary<string>();
  //Configure the width and height to display for the Banner, 
  //and whether to use pixel units (only effective for iOS; Android uses pixel units). 
  //Note that banner ads on different platforms have certain limits. 
  //For example, if you configure a Pangle banner ad at 640*100, 
  //to fill the full screen width, calculate the height H = (screen width * 100) / 640;
  //then the size in the load extra is (screen width: H).
  ATSize bannerSize = new ATSize(this.screenWidth, 100, true);
  jsonmap.Add(ATBannerAdLoadingExtra.kATBannerAdLoadingExtraBannerAdSizeStruct, bannerSize);

  //Added in v5.6.5, only for AdMob's adaptive Banner
  jsonmap.Add(ATBannerAdLoadingExtra.kATBannerAdLoadingExtraInlineAdaptiveWidth, bannerSize.width);
  jsonmap.Add(ATBannerAdLoadingExtra.kATBannerAdLoadingExtraInlineAdaptiveOrientation, ATBannerAdLoadingExtra.kATBannerAdLoadingExtraInlineAdaptiveOrientationCurrent);

  ATBannerAd.Instance.loadBannerAd(mPlacementId_native_all, jsonmap);
}

Please continue reading to learn how to receive notifications about Banner ad events, such as load success/failure, display, and click.

Currently, there are two methods to display a banner ad.

  1. Display the banner at the top of the screen:
java Copy
ATBannerAd.Instance.showBannerAd(mPlacementId_native_all, ATBannerAdLoadingExtra.kATBannerAdShowingPisitionTop);
  1. Display the banner at the bottom of the screen:
java Copy
ATBannerAd.Instance.showBannerAd(mPlacementId_native_all, ATBannerAdLoadingExtra.kATBannerAdShowingPisitionBottom);

When using a predefined position to display a banner ad, AnyThinkSDK has already accounted for Safe Area-related blank areas such as the notch area.

java Copy
public void showBannerAd() 
{
    // Please keep the width and height consistent with the size passed when loading the ad, and set the x and y coordinates as needed.
    ATRect arpuRect = new ATRect(0,70, screenWidth, 100, true);
    ATBannerAd.Instance.showBannerAd(mPlacementId_native_all, arpuRect);
}

The trailing parameter passed to the ATRect class constructor indicates whether to use pixels (only effective for iOS). For example, on an iPhone 6, if you pass 30, 120, 300, 450 for x, y, width, and height respectively, the actual values passed to the Objective-C code on an iPhone 7 will be 15, 60, 150, 225; these values will be 10, 40, 100, 150; that is, the final values will depend on the screen ratio of the target device.

When using the scenario feature:

java Copy
public void showBannerAd()
{
    Dictionary<string string=""> jsonmap = new Dictionary<string string="">();
    jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenarioID);
    ATBannerAd.Instance.showBannerAd(mPlacementId_banner_all,ATBannerAdLoadingExtra.kATBannerAdShowingPisitionBottom, jsonmap);
    //ATBannerAd.Instance.showBannerAd(mPlacementId_native_all, arpuRect, jsonmap);
}

If needed, use the following code to remove the Banner from the screen:

java Copy
public void removeBannerAd() 
{
    ATBannerAd.Instance.cleanBannerAd(mPlacementId_native_all);
}

If you only want to temporarily hide the Banner (instead of removing it from the screen), use the code here:

java Copy
public void hideBannerAd() 
{
    ATBannerAd.Instance.hideBannerAd(mPlacementId_native_all);
}

After hiding the Banner, you can redisplay it using the following code:

java Copy
public void reshowBannerAd()
{
    ATBannerAd.Instance.showBannerAd(mPlacementId_native_all);
}

Note: Please note that the showBannerAd method here does not accept a rect parameter, which is different from when you display the Banner ad for the first time.

The difference between removing a Banner ad and hiding a Banner ad is that removing it from the screen also destroys it (meaning you must load the Banner ad again before displaying it), whereas to hide a Banner, you simply need to call the showBannerAd method to redisplay the previously hidden Banner ad without passing the ATRect parameter.

For callback information details, please see: Callback Information Description

Use the following code to implement multiple listeners:

java Copy
// Ad loading succeeded
ATBannerAd.Instance.client.onAdLoadEvent += onAdLoad;
// Ad loading failed
ATBannerAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
// Ad display succeeded
ATBannerAd.Instance.client.onAdImpressEvent += onAdImpress;
// Ad auto-refresh succeeded
ATBannerAd.Instance.client.onAdAutoRefreshEvent += onAdAutoRefresh;
// Ad auto-refresh failed
ATBannerAd.Instance.client.onAdAutoRefreshFailureEvent += onAdAutoRefreshFail;
// Ad clicked
ATBannerAd.Instance.client.onAdClickEvent += onAdClick;
// Ad dismissed
ATBannerAd.Instance.client.onAdCloseEvent += onAdCloseButtonTapped;      

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.):

java Copy
// sender is the ad type object, erg is the returned information
// Load ad
// Ad auto-refresh succeeded
public void onAdAutoRefresh(object sender,ATAdEventArgs erg)
{
    Debug.Log("Developer callback onAdAutoRefresh :" + erg.placementId );
}
// Ad auto-refresh failed
public void onAdAutoRefreshFail(object sender,ATAdErrorEventArgs erg )
{
    Debug.Log("Developer callback onAdAutoRefreshFail : "+ erg.placementId );
}
// Ad clicked
public void onAdClick(object sender,ATAdEventArgs erg)
{
    Debug.Log("Developer callback onAdClick :" + erg.placementId);
}

// Ad display succeeded
public void onAdImpress(object sender,ATAdEventArgs erg)
{
    Debug.Log("Developer callback onAdImpress :" + erg.placementId);
}
// 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 + "--code:" + erg.code + "--msg:" + erg.message);
}
// Ad close button was clicked
public void onAdCloseButtonTapped(object sender,ATAdEventArgs erg)
{
    Debug.Log("Developer callback onAdCloseButtonTapped :" + erg.placementId);
}

    
Previous
Fully automatic loading of interstitial ads
Next
Native
Last modified: 2026-07-16Powered by