1. Integrate Tips
● Custom Width and Height
- The custom width and height should be consistent with the dimensions configured in the TopOn dashboard, and adjustments should be made based on the actual effect.
● Auto Refresh
- The automatic refresh function is triggered only when ATBannerView is added to the container and is visible.
- It is recommended to disable the automatic refresh feature of network (Inmobi, Mopub, Mintegral, Pangle) and use only the automatic refresh provided by TopOn.
- After enabling the automatic refresh feature, you only need to call
load()
once. Subsequent ad displays and refreshes will be automatically performed by the TopOn SDK.
● About Destroy
- When you no longer need to display the banner ad, you should remove ATBannerView from your layout and call
ATBannerView#destroy()
to destroy the current ad resources.
2. Load and Show a Banner Ad
💡Please call this function in advance to reduce user waiting time.
ATBannerView mBannerView = new ATBannerView(activity);
mBannerView.setPlacementId("your placment id");
//Set the layout parameters for ATBannerView
//Set a width value, such as the screen width
int width = getResources().getDisplayMetrics().widthPixels;
int height = ViewGroup.LayoutParams.WRAP_CONTENT;
mBannerView.setLayoutParams(new FrameLayout.LayoutParams(width, height));
//Add ATBannerView to the layout container
//If you need to manually control when to display ads, you can choose the appropriate time to call this method based on your own needs
frameLayout.addView(mBannerView);
mBannerView.setBannerAdListener(new ATBannerListener() {
@Override
public void onBannerLoaded() {}
@Override
public void onBannerFailed(AdError adError) {
//Note: Do not call load() here, as it may lead to an ANR error
}
@Override
public void onBannerClicked(ATAdInfo atAdInfo) {}
@Override
public void onBannerShow(ATAdInfo atAdInfo) {}
@Override
public void onBannerClose(ATAdInfo atAdInfo) {
if (mBannerView != null && mBannerView.getParent() != null) {
((ViewGroup) mBannerView.getParent()).removeView(mBannerView);
}
}
@Override
public void onBannerAutoRefreshed(ATAdInfo atAdInfo) {}
@Override
public void onBannerAutoRefreshFail(AdError adError) {}
});
//You can use ATAdConst.KEY.AD_WIDTH and ATAdConst.KEY.AD_HEIGHT to set the width and height of the banner ad returned by the network
//The networks that currently support setting width and height are: Mintegral, Pangle, UnityAds, Yandex, and Admob.
//Example: Assuming the banner ad's dimensions are 320x50.
Map localMap = new HashMap<>();
localMap.put(ATAdConst.KEY.AD_WIDTH, dip2px(320));
localMap.put(ATAdConst.KEY.AD_HEIGHT, dip2px(50));
mBannerView.setLocalExtra(localMap);
mBannerView.loadAd();
public int dip2px(int dipValue) {
float scale = getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
3. Ad Scenario Statistics
Track the scene arrival rates, which are presented in the TopOn dashboard under Report -> Funnel Report -> Scenario.
- First, call
entryAdScenario()
- Then, call
setShowConfig()
- Finally, display the ad
void entryAdScenario(String placementId, String scenarioId) | Enter the business scenario to track the current cache status of the ad placement. For specific usage, refer to the ad scenarios. placementId: ad placement id, you can refer to here scenarioId: ad scenario id (optional; passing null will record statistics under the default scenario) |
void setShowConfig(ATShowConfig showConfig) | Set the ad scenario (for the upcoming ad display) showConfig: extra parameters that can be passed in at the time of display include: 1. ATShowConfig#showCustomExt(String showCustomExt) : you can pass in custom parameters for display, which will be returned through ATAdInfo#getShowCustomExt() .2. ATShowConfig#scenarioId(String scenarioId) : you can pass in the ad scenario ID. |
ATBannerView.entryAdScenario("your placement id", "your scenario id");
ATShowConfig.Builder builder = new ATShowConfig.Builder();
builder.scenarioId("your scenario id");
builder.showCustomExt("your custom data");
// Note: You need to call this function before displaying the ad
mBannerView.setShowConfig(builder.build());
4. Advanced
Preset strategy : By configuring preset strategies, you can improve the ad loading performance during the app's initial cold start.
Customized banner ads : Native ad source is allowed to be mixed with banner placement. Refer to here to obtain more information about AD Format Mixed.
5. Note
● AdMob adaptive banner ads
TopOn supports AdMob adaptive banners, with the recommendation to use anchored adaptive banner ads.
You can refer to the following code to set the type of the adaptive banner, determine which screen orientation it should adapt to, and set the banner's width (in pixels):
ATBannerView mBannerView = new ATBannerView(activity);
mBannerView.setPlacementId("your placement id");
Map localExtra = new HashMap<>();
localExtra.put(AdmobATConst.ADAPTIVE_TYPE, AdmobATConst.ADAPTIVE_ANCHORED);
//localExtra.put(AdmobATConst.ADAPTIVE_TYPE, AdmobATConst.ADAPTIVE_INLINE);
localExtra.put(AdmobATConst.ADAPTIVE_ORIENTATION, AdmobATConst.ORIENTATION_CURRENT);
//localExtra.put(AdmobATConst.ADAPTIVE_ORIENTATION, AdmobATConst.ORIENTATION_PORTRAIT);
//localExtra.put(AdmobATConst.ADAPTIVE_ORIENTATION, AdmobATConst.ORIENTATION_LANDSCAPE);
localExtra.put(AdmobATConst.ADAPTIVE_WIDTH, width);
mBannerView.setLocalExtra(localExtra);
mBannerView.loadAd();
Note: When using AdMob adaptive banner ads, you should not restrict the height of the Banner's parent container. An example is as follows:
mBannerView.setLayoutParams(new FrameLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT)); mBannerView.loadAd();