Native Ads
With the release of MAS 4.6, you can now use Native Ads in your games! Here are a few things you need to know in order to get started with this ad type:
- Native ads in MAS are available in 3 sizes: Small, Medium, or Custom. Small has a ratio of 3:1, and Medium has a ratio of 6:5. See the table below for recommended sizes.
- Custom means you show a Native Ad in a way thatās consistent with its existing UI design, please click hereĀ to follow the custom native ad integration instruction.
- Currently, you may only use 1 size of Native Ad for your game, which you can specify during the submission of your game. Should you need to change the size, please contact the support team via the support chat.
Small Size (3:1) | Medium Size (6:5) |
300 x 100* | 600 x 500 |
1. Add the AdView
The first step toward displaying a native is to placeĀ Yodo1MasNativeAdView
Ā in the layout for the Activity or Fragment in which youād like to display it. The easiest way to do this is to add one to the corresponding XML layout file. Hereās an example that shows an activityāsĀ Yodo1MasNativeAdView
:
You can alternatively createĀ Yodo1MasNativeAdView
Ā programmatically:
Yodo1MasNativeAdView nativeAdView =
new Yodo1MasNativeAdView(this);
nativeAdView.setLayoutParams(new
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp2px(300)));
// TODO: Add nativeAdView to your view hierarchy.
val nativeAdView = Yodo1MasNativeAdView(this)
nativeAdView.setLayoutParams(ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, dp2px(300)))
// TODO: Add nativeAdView to your view hierarchy.
2. Load an ad
Once theĀ Yodo1MasNativeAdView
Ā is in place, the next step is to load an ad. Thatās done with theĀ loadAd()
Ā method in theĀ Yodo1MasNativeAdView
Ā class.
Hereās an example that shows how to load an ad in theĀ onCreate()
Ā method of anĀ Activity
:
3. Ad events
To further customize the behavior of your ad, you can hook onto a number of events in the adās lifecycle: loading, opening, closing, and so on. You can listen for these events through theĀ Yodo1MasNativeAdListener
Ā class.
nativeAdView.setAdListener(new Yodo1MasNativeAdListener() {
@Override public void onNativeAdLoaded(Yodo1MasNativeAdView nativeAdView) {
// Code to be executed when an ad finishes loading.
}
@Override public void onNativeAdFailedToLoad(Yodo1MasNativeAdView nativeAdView, @NonNull Yodo1MasError error) {
// Code to be executed when an ad request fails.
}
});
nativeAdView.setAdListener(object: Yodo1MasNativeAdListener {
override fun onNativeAdLoaded(nativeAdView: Yodo1MasNativeAdView ? ) {
// Code to be executed when an ad finishes loading.
}
override fun onNativeAdFailedToLoad(nativeAdView: Yodo1MasNativeAdView ? , error : Yodo1MasError) {
// Code to be executed when an ad request fails.
}
})