ATBannerAd:
API | Parameters | Description |
---|---|---|
loadBannerAd | string placementid , Dictionary | Loading ads |
setListener | ATBannerAdListener listener | Set the listening callback interface(Abandoned after version 5.9.51) For specific reference to how to set the listener: Banner ad event setting instructions |
showBannerAd | string placementid, string position | Initial display of ads postion: ATBannerAdLoadingExtra.kATBannerAdShowingPisitionTop (displayed at the top of the screen) ATBannerAdLoadingExtra.kATBannerAdShowingPisitionBottom (displayed at the bottom of the screen) |
checkAdStatus | string placementid | |
getValidAdCaches | string placementid | (new in v5.7.54)Get successfully loaded All ad cache information (JSON string) (refer to ATCallbackInfo description) |
hideBannerAd | string placementid | Hide ads |
showBannerAd | string placementid | Show hidden ads |
cleanBannerAd | string placementid | Remove 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 jsonmap = new Dictionary();
//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.
There are currently two methods 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 jsonmap = new Dictionary();
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>
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;
Advanced listening The setting
// Advertising source starts loading
ATBannerAd.Instance.client.onAdSourceAttemptEvent += startLoadingADSource;
// Advertising source loading completed
ATBannerAd.Instance.client.onAdSourceFilledEvent += finishLoadingADSource;
//Ad source loading failed
ATBannerAd.Instance.client.onAdSourceLoadFailureEvent += failToLoadADSource;
// Advertising sources start bidding
ATBannerAd.Instance.client.onAdSourceBiddingAttemptEvent += startBiddingADSource;
// Advertising source bidding successful
ATBannerAd.Instance.client.onAdSourceBiddingFilledEvent += finishBiddingADSource;
// Advertising source bidding failed
ATBannerAd.Instance.client.onAdSourceBiddingFailureEvent += failBiddingADSource;
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);
}
// 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------");
}
To get notified about various Banner ad events (load success/failure, impressions and clicks), just define a Implementation class of ATBannerAdListener interface: (Note: For Android, all callback methods are not in Unity's Main thread)
class BannerCallback : ATBannerAdListener
{
//Advertisement automatically refreshed successfully
public void onAdAutoRefresh(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onAdAutoRefresh :" + placementId);
}
//Ad auto-refresh failed
public void onAdAutoRefreshFail(string placementId, string code, string message)
{
Debug.Log("Developer callback onAdAutoRefreshFail : "+ placementId + "--code:" + code + "--msg:" + message);
}
//ad clicked
public void onAdClick(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onAdClick :" + placementId);
}
//This callback will no longer be executed after v5.5.3, and will go to the onAdCloseButtonTapped method callback.
public void onAdClose(string placementId)
{
Debug.Log("Developer callback onAdClose :" + placementId);
}
//Advertisement displayed successfully
public void onAdImpress(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onAdImpress :" + placementId);
}
//Advertisement loaded successfully
public void onAdLoad(string placementId)
{
Debug.Log("Developer callback onAdLoad :" + placementId);
}
//Ad loading failed
public void onAdLoadFail(string placementId, string code, string message)
{
Debug.Log("Developer callback onAdLoadFail : : " + placementId + "--code:" + code + "--msg:" + message);
}
//Ad close button clicked
public void onAdCloseButtonTapped(string placementId, ATCallbackInfo callbackInfo)
{
Debug.Log("Developer callback onAdCloseButtonTapped :" + 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 bannerScene.cs demo project.