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