A Native Ad in Meson consists of two parts :
Ensure that you use the exact versions to skip facing any errors due to using an older version.
Add the following to your app's build.gradle file.
implementation "com.google.android.exoplayer:exoplayer-core:2.17.1"
implementation "com.google.android.exoplayer:exoplayer-ui:2.17.1"
implementation 'com.squareup.picasso:picasso:2.8'
To create a native ad, design a Native ad template in your app.
Meson provides you with complete flexibility to design your NativeAdView
. Design the following assets:
Name | Asset Type | Is Mandatory? | Description |
---|---|---|---|
Title |
TextView |
Yes | The maximum number of characters allowed is 25. |
Description |
TextView |
No | The maximum number of characters allowed is 100. |
MediaView |
MesonMediaView |
Yes | Body of the ad. It can consist of an Image/Video. |
AdSponsored |
TextView |
Yes | The maximum number of characters allowed is 15. |
CallToAction(CTA) |
TextView |
No | The maximum number of characters allowed is 15. |
Icon |
MesonImageView |
No | A small image is present in the ad. |
AdChoice |
MesonImageView |
No | Place adChoices at the right-top of the view. |
Rating |
TextView |
No | Rating of the ad |
Meson SDK on the top-right corner renders the AdChoices Icon. It is highly recommended not to render any essential asset, especially assets with click actions in the top right corner (Ad Choices Icon is 2px by 2px).
Click here to download the sample Ad template. Remember that the template will be defined under MesonNativeAdContainer
.
var nativeAdContainer: MesonNativeAdContainer = findViewById(R.id.native_ad_container)
nativeAdContainer.setTitleViewId(R.id.native_ad_title)
nativeAdContainer.setAdChoicesViewId(R.id.native_ad_choices)
nativeAdContainer.setIconViewId(R.id.native_ad_icon)
nativeAdContainer.setMediaViewId(R.id.native_ad_media)
nativeAdContainer.setDescriptionViewId(R.id.native_ad_desc)
nativeAdContainer.setCTAViewId(R.id.native_ad_cta)
nativeAdContainer.setSponsoredViewId(R.id.native_ad_sponsored)
nativeAdContainer.setRatingViewId(R.id.native_ad_rating)
MesonNativeAdContainer nativeAdContainer = view.findViewById(R.id.native_ad_container)
nativeAdContainer.setTitleViewId(R.id.native_ad_title)
nativeAdContainer.setAdChoicesViewId(R.id.native_ad_choices)
nativeAdContainer.setIconViewId(R.id.native_ad_icon)
nativeAdContainer.setMediaViewId(R.id.native_ad_media)
nativeAdContainer.setDescriptionViewId(R.id.native_ad_desc)
nativeAdContainer.setCTAViewId(R.id.native_ad_cta)
nativeAdContainer.setSponsoredViewId(R.id.native_ad_sponsored)
nativeAdContainer.setRatingViewId(R.id.native_ad_rating)
If you miss to Initialize the SDK, this method will fail to return a response.
After your adunitId
is generated, you can find it on the Meson UI. Add adunitId
into the MesonInterstitial
object and pass the ActivityContext
.
val nativeAd = MesonNative(this, "AD_UNIT_ID")
MesonNative nativeAd = new MesonNative(this, "AD_UNIT_ID");
Track the ad lifecycle for native ads. All the available events for native ads are listed below.
Set the Native Ad within the following onAdLoadSucceeded
callback.
nativeAd.setAdListener(object: MesonNativeAdLoadListener() {
override fun onAdLoadSucceeded(ad: NativeAd) {
//add the nativeAd to the nativeAdContainer here:nativeAdContainer.setNativeAd(nativeAd)
}
override fun onAdLoadFailed(status: MesonAdRequestStatus) {
}
})
nativeAd.setAdListener(new MesonNativeAdLoadListener() {
@Override
public void onAdLoadSucceeded(@NonNull NativeAd nativeAd) {
super.onAdLoadSucceeded(nativeAd);
}
@Override
public void onAdLoadFailed(@NonNull MesonAdRequestStatus mesonAdRequestStatus) {
super.onAdLoadFailed(mesonAdRequestStatus);
}
});
The publisher can request a native ad by invoking this method. This will request an ad from all demand sources, select a winner, and make it available on the SDK.
//use load() to make your native ad request
nativeAd.load()
nativeAd.load();
Events such as clicks, impressions, video play/pause, and others can be tracked by registering with the Native Ad Listener.
nativeAdContainer.setNativeAdListener(object: MesonNativeAdListener() {
override fun onAdClicked(params: HashMap<String, Any>) {
}
override fun onAdImpression(mesonAdData: MesonAdData?) {
}
override fun onUserLeftApplication() {
}
override fun onVideoStarted() {
}
override fun onVideoPaused() {
}
override fun onVideoResumed() {
}
override fun onVideoCompleted() {
}
})
nativeAdContainer.setNativeAdListener(new MesonNativeAdListener() {
@Override
public void onVideoStarted() {
super.onVideoStarted();
}
@Override
public void onVideoResumed() {
super.onVideoResumed();
}
@Override
public void onVideoPaused() {
super.onVideoPaused();
}
@Override
public void onVideoCompleted() {
super.onVideoCompleted();
}
@Override
public void onUserLeftApplication() {
super.onUserLeftApplication();
}
@Override
public void onAdImpression(@Nullable MesonAdData mesonAdData) {
super.onAdImpression(mesonAdData);
}
@Override
public void onAdClicked(@NonNull HashMap<String, Object> hashMap) {
super.onAdClicked(hashMap);
}
});
The ad is returned to the user in the onAdLoadSucceeded
callback. You must set the ad in the native ad container to start rendering it.
//add the nativeAd to the nativeAdContainer, place this within the onAdLoadSucceeded callback
nativeAdContainer.setNativeAd(nativeAd)
//add the nativeAd to the nativeAdContainer, place this within the onAdLoadSucceeded callback
nativeAdContainer.setNativeAd(nativeAd);
Use this method when a recycler view shows a native ad.
override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
holder.nativeAdContainer.recycle()
}
@Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
holder.nativeAdContainer.recycle();
}
Use this method when the ad container is no longer needed. We recommend using this onDestroy of the Activity of which the native container is part.
nativeAdContainer.destroy()
nativeAdContainer.destroy();