Menu

Banner Ad

1. Suggestions for access process

  1. When starting the application, execute ATBannerAd#loadBannerAd to load the advertisement
  2. When the advertisement is successfully loaded and displayed for the first time, execute ATBannerAd# showBannerAd(string placementid, string position) displays ads
  3. If you need to hide the ad, you can execute ATBannerAd#hideBannerAd; if you need to re-display it after hiding, you need to execute ATBannerAd#showBannerAd( string placementid)
  4. You can configure the refresh time to turn on the automatic refresh function through TopOn background advertising slot-advanced settings

2. API Description

ATBannerAd:

API ParametersDescription
loadBannerAdstring placementid , Dictionary<string,string> extraLoading ads
setListenerATBannerAdListener listenerSet the listening callback interface(Abandoned after version 5.9.51) For specific reference to how to set the listener: Banner ad event setting instructions
showBannerAdstring placementid, string positionInitial display of ads
postion: ATBannerAdLoadingExtra.kATBannerAdShowingPisitionTop (displayed at the top of the screen)
ATBannerAdLoadingExtra.kATBannerAdShowingPisitionBottom (displayed at the bottom of the screen)
hideBannerAdstring placementidHide ads
showBannerAdstring placementidShow hidden ads
cleanBannerAd string placementidRemove ads

3. Load Banner ads

Use the following code to load Banner ads

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,object>();
    //Configure the width and height of the Banner to be displayed, and whether to use pixel as the unit (only valid for iOS, Android uses pixel as the unit). Note that banner ads on different platforms have certain restrictions. For example, the configured pangolin banner ad is 640*100. In order to be able to fill After calculating the screen width, calculate the height H = (screen width * 100)/640; then the extra size in load is (screen width: H).
    ATSize bannerSize = new ATSize(this.screenWidth, 100, true);
    jsonmap.Add(ATBannerAdLoadingExtra.kATBannerAdLoadingExtraBannerAdSizeStruct, bannerSize);

    //New in v5.6.5, only adaptive Banner for Admob
    jsonmap.Add(ATBannerAdLoadingExtra.kATBannerAdLoadingExtraInlineAdaptiveWidth, bannerSize.width);
    jsonmap.Add(ATBannerAdLoadingExtra.kATBannerAdLoadingExtraInlineAdaptiveOrientation, ATBannerAdLoadingExtra.kATBannerAdLoadingExtraInlineAdaptiveOrientationCurrent);

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

Please continue reading to know How to get notified about Banner ad events such as loading success/failure, impressions and clicks.

4. Display Banner ads

There are currently two methods to display banner ads.

4.1 Use predefined positions to display banner ads

4.2 Use ATRect to display banner ads

public void showBannerAd() 
{
    // Please match the width and height of the size passed in when loading the ad, and set the x and y axis coordinates as required.
    ATRect arpuRect = new ATRect(0,70, screenWidth, 100, true);
    ATBannerAd.Instance.showBannerAd(mPlacementId_native_all, arpuRect);
}

The last parameter passed to the constructor of the ATRect class indicates whether to use pixels< span style="color: rgb(44, 62, 80);">(only valid for iOS). For example, on 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 iPhone 7 will be 15, 60, 150, 225 These values will be 10, 40, 100, 150; that is, the final value will be determined by the screen ratio of the target device.

When using Scene Function:

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 from On screenRemoveBanner:

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

If you only want to temporarily Hide Banner (rather than remove from screen), please Use the code here:

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

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

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

Note: Please note that the showBannerAd method here does not accept a rect parameter, unlike when you first display a Banner ad.

The difference between removing a Banner ad and hiding a Banner ad is that removing a Banner ad from the screen also destroys it (which means that before showing it again, The Banner ad must be loaded first), and to hide the Banner, you only need to call the showBannerAd method to redisplay the previously hidden Banner ad Do not pass the ATRect parameter< /strong>

5. Implement Banner event Listener

For details of callback information, please see: Callback information description

Use the following code to implement multiple listeners

        //Advertisement loaded successfully
        ATBannerAd.Instance.client.onAdLoadEvent += onAdLoad;
        //Ad loading failed
        ATBannerAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
        //Advertisement displayed successfully
        ATBannerAd.Instance.client.onAdImpressEvent += onAdImpress;
        //Advertisement automatically refreshed successfully
        ATBannerAd.Instance.client.onAdAutoRefreshEvent += onAdAutoRefresh;
        //Ad auto-refresh failed
        ATBannerAd.Instance.client.onAdAutoRefreshFailureEvent += onAdAutoRefreshFail;
        //ad clicked
        ATBannerAd.Instance.client.onAdClickEvent += onAdClick;
        //ads off
        ATBannerAd.Instance.client.onAdCloseEvent += onAdCloseButtonTapped;      

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
    //Load ads
    //Advertisement automatically refreshed successfully
    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);
    }

    //Advertisement displayed successfully
    public void onAdImpress(object sender,ATAdEventArgs erg)
    {
        Debug.Log("Developer callback onAdImpress :" + erg.placementId);
    }
    //Advertisement loaded successfully
    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 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: 2025-05-30Powered by