Native
Native ad is a flexible type of advertising. You can adapt the display to your UI by preparing a template.
Appodeal provides 4 options to implement the layout of native ads 3 templates + your custom
implementation
All of them are inherited from the same NativeAdView
class.
NativeAdView
consists of the following components:
NativeIconView
- Icon of the native ad.AdAttributionView
- Advertising Indicator. This is a TextView labeled "Ad".TitleVIew
- Title of the native ad.DescriptionView
- Text descriptionView of the native ad.RatingBarView
- Rating of the app in [0-5] range.NativeMediaView
- Media content of the native ad.CallToActionView
- Button for click.AdChoiceView
- Special ad icon provided by ad network.
Templates implementation:
To display them, all you need to do is:
- Create programmatically or in your layout file one of View template classes
Native template views classes:
NativeAdViewNewsFeed
NativeAdViewAppWall
NativeAdViewContentStream
NativeAdView for custom implementation:
To display it, all you need to do is:
- Create a
NativeAdVIew
class programmatically or in your layout file - Inside the created
NativeAdView
, arrange all theView
/IconView
/MediaView
you need for displaying it in any style you prefer - Bind programmatically or in your layout file all necessary
View
/IconView
/MediaView
.
Native view for a Custom Implementation:
NativeAdView
Integration guide
- For templates
- For custom layout
- Create programmatically or in your layout file one of View template classes:
- XML
- Kotlin
- Java
<com.appodeal.ads.nativead.NativeAdViewNewsFeed
android:id="@+id/native_news_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.appodeal.ads.nativead.NativeAdViewAppWall
android:id="@+id/native_app_wall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.appodeal.ads.nativead.NativeAdViewContentStream
android:id="@+id/native_content_stream"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
val newsFeedView = NativeAdViewNewsFeed(context)
val appWallView = NativeAdViewAppWall(context)
val contentStreamView = NativeAdViewContentStream(context)
NativeAdViewNewsFeed newsFeedView = new NativeAdViewNewsFeed(context);
NativeAdViewAppWall appWallView = new NativeAdViewAppWall(context);
NativeAdViewContentStream contentStreamView = new NativeAdViewContentStream(context);
- Get a view instance from layout OR add a programmatically created ViewTemplate to your View hierarchy:
- Kotlin
- Java
val newsFeedView = findViewById<NativeAdViewNewsFeed>(R.id.native_news_feed);
val appWallView = findViewById<NativeAdViewAppWall>(R.id.native_app_wall);
val contentStreamView = findViewById<NativeAdViewContentStream>(R.id.native_content_stream);
rootView.addView(newsFeedView)
rootView.addView(appWallView)
rootView.addView(contentStreamView)
NativeAdViewNewsFeed newsFeedView = findViewById(R.id.native_news_feed);
NativeAdViewAppWall appWallView = findViewById(R.id.native_app_wall);
NativeAdViewContentStream contentStreamView = findViewById(R.id.native_content_stream);
rootView.addView(newsFeedView);
rootView.addView(appWallView);
rootView.addView(contentStreamView);
- When the NativeAd is loaded just register it
- For single NativeAd
- For several NativeAd instances
- Kotlin
- Java
if (Appodeal.isLoaded(Appodeal.NATIVE)) {
newsFeedView.registerView(Appodeal.getNativeAdCount(1))
}
if (Appodeal.isLoaded(Appodeal.NATIVE)) {
newsFeedView.registerView(Appodeal.getNativeAdCount(1));
}
- Kotlin
- Java
val needToShow = 3
if (Appodeal.getAvailableNativeAdsCount() >= needToShow) {
val nativeAds = Appodeal.getNativeAdCount(needToShow)
newsFeedView.registerView(nativeAds[0])
appWallView.registerView(nativeAds[1])
contentStreamView.registerView(nativeAds[2])
}
int needToShow = 3;
if (Appodeal.getAvailableNativeAdsCount() >= needToShow) {
List<NativeAd> nativeAds = Appodeal.getNativeAdCount(needToShow);
newsFeedView.registerView(nativeAds.get(0));
appWallView.registerView(nativeAds.get(1));
contentStreamView.registerView(nativeAds.get(2);
}
- When the display has been terminated and you no longer plan to use the NativeAdView, you should call the destroy method:
- Kotlin
- Java
nativeAdView.destroy()
nativeAdView.destroy();
General requirements:
NativeAdView
must have min height as 32dp;NativeMediaView
must have mim size as 120dp x 120dp;- The
AdAttributionView
must clearly mark your nativeAd as "Ad" so that users don't mistake them for content; - You are allowed to scale the
NativeIconView
orNativeMediaView
down without modifying the aspect ratio; - You are allowed to crop the
NativeIconView
orNativeMediaView
symmetrically by up to 20% in only one dimension (height or width).
- Create your markdown with NativeAdView as root:
You can build a layout with any style, arrangement of elements and with any type of
ViewGroup
(ConstrainLayout
, RelativeLayout
, FrameLayout
)
<?xml version="1.0" encoding="utf-8"?>
<com.appodeal.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nativeAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adChoicePosition="end_top"
app:callToActionViewId="@id/callToActionView"
app:descriptionViewId="@id/descriptionView"
app:iconViewId="@id/iconView"
app:mediaViewId="@id/mediaView"
app:ratingViewId="@id/ratingView"
app:titleViewId="@id/titleView"
app:adAttributionViewId="@+id/ad_attribution">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.appodeal.ads.nativead.NativeIconView
android:id="@+id/iconView"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center_vertical"
android:layout_margin="5dp" />
<TextView
android:id="@+id/ad_attribution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:background="@color/red" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/titleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView
android:id="@+id/descriptionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="3" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="horizontal">
<RatingBar
android:id="@+id/ratingView"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="@+id/callToActionView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="30dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<com.appodeal.ads.nativead.NativeMediaView
android:id="@+id/mediaView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</com.appodeal.ads.nativead.NativeAdView>
Requirements for NativeAdView
elements
Name of view | Type | Mandatory | Description |
---|---|---|---|
titleView | TextView | Mandatory | Title of the native ad. Maximum 25 symbols of the title should always be displayed. You can add ellipsis at the end if the title is longer. |
callToActionView | Button | Mandatory | Call-to-action button. Should be displayed without truncation on a visible button. |
descriptionView | TextView | Optional | Text description of the native ad. If you choose to display the description, you should display maximum 100 characters. You can add ellipsis at the end. |
ratingView | RatingBar | Optional | Rating of the app in [0-5] range |
adAttributionView | TextView | Mandatory | Advertising Indicator. This is a TextView labeled "Ad". You can specify the color of the text and background. See adAttribution settings. You can place it anywhere inside the NativeAdView . |
adChoicesView | ViewGroup | Attach automatically | Special ad icon provided by ad network. If SDK received AdChoice from ad network, it attached it automatically. You can specify a position in one of the corners of the NativeAdView . See setAdChoice position |
iconView | NativeIconView | Mandatory/Optional | Media content of the native ad. |
mediaView | NativeMediaView | Mandatory/Optional | Icon of the native ad. |
NativeAdView
must contain either NativeIconView
or NativeMediaView
.
The titleView
, callToActionView
and adAttributionView
has to be added in any cases.
- Set ids of all child views of
NativeAdView
.
You can do this either in the xml file of markdown (recommended way) or programmatically
- XML
- Kotlin
- Java
<com.appodeal.ads.nativead.NativeAdView
app:callToActionViewId="@id/callToActionView"
app:descriptionViewId="@id/descriptionView"
app:iconViewId="@id/iconView"
app:mediaViewId="@id/mediaView"
app:ratingViewId="@id/ratingView"
app:titleViewId="@id/titleView">
app:adAttributionViewId="@id/adAttribution">
val nativeAdView: NativeAdView = ...
nativeAdView.titleViewId = R.id.titleView
nativeAdView.callToActionViewId = R.id.callToActionView
nativeAdView.descriptionViewId = R.id.descriptionView
nativeAdView.ratingViewId = R.id.ratingView
nativeAdView.iconViewId = R.id.iconView
nativeAdView.mediaViewId = R.id.mediaView
nativeAdView.adAttributionViewId = R.id.adAttribution
// OR
nativeAdView.titleView = findViewById(R.id.titleView)
nativeAdView.callToActionView = findViewById(R.id.callToActionView)
nativeAdView.descriptionView = findViewById(R.id.descriptionView)
nativeAdView.ratingView = findViewById(R.id.ratingView)
nativeAdView.iconView = findViewById(R.id.iconView)
nativeAdView.mediaView = findViewById(R.id.mediaView)
nativeAdView.adAttributionView = findViewById(R.id.adAttribution)
NativeAdView nativeAdView: NativeAdView = ...
nativeAdView.setTitleViewId(R.id.titleView);
nativeAdView.setCallToActionViewId(R.id.callToActionView);
nativeAdView.setDescriptionViewId(R.id.descriptionView);
nativeAdView.setRatingViewId(R.id.ratingView);
nativeAdView.setIconViewId(R.id.iconView);
nativeAdView.setMediaViewId(R.id.mediaView);
nativeAdView.setAdAttributionViewId(R.id.adAttribution);
// OR
nativeAdView.setTitleView(findViewById(R.id.titleView));
nativeAdView.setCallToActionView(findViewById(R.id.callToActionView));
nativeAdView.setDescriptionView(findViewById(R.id.descriptionView));
nativeAdView.setRatingView(findViewById(R.id.ratingView));
nativeAdView.setIconView(findViewById(R.id.iconView));
nativeAdView.setMediaView(findViewById(R.id.mediaView));
nativeAdView.setAdAttributionView(findViewById(R.id.adAttribution));
- When the
NativeAd
is loaded just register it for showing:
- For single NativeAd
- For several NativeAd instances
- Kotlin
- Java
if (Appodeal.isLoaded(Appodeal.NATIVE)) {
newsFeedView.registerView(Appodeal.getNativeAdCount(1))
}
if (Appodeal.isLoaded(Appodeal.NATIVE)) {
newsFeedView.registerView(Appodeal.getNativeAdCount(1));
}
- Kotlin
- Java
val needToShow = 3
if (Appodeal.getAvailableNativeAdsCount() >= needToShow) {
val nativeAds = Appodeal.getNativeAdCount(needToShow)
nativeAdView1.registerView(nativeAds[0])
nativeAdView2.registerView(nativeAds[1])
nativeAdView3.registerView(nativeAds[2])
}
int needToShow = 3;
if (Appodeal.getAvailableNativeAdsCount() >= needToShow) {
List<NativeAd> nativeAds = Appodeal.getNativeAdCount(needToShow);
nativeAdView1.registerView(nativeAds.get(0));
nativeAdView2.registerView(nativeAds.get(1));
nativeAdView3.registerView(nativeAds.get(2));
}
- When the display has been terminated and you no longer plan to use the
NativeAdView
, you should call thedestroy
method:
- Kotlin
- Java
nativeAdView.destroy()
nativeAdView.destroy();
If you want to show a new NativeAd inside used nativeAdView, just call
nativeAdView.registerView(newNativeAd)
method.
Check If Ad Is Loaded
To check if at least 1 instance of NativeAd
is loaded, use the method:
- Kotlin
- Java
Appodeal.isLoaded(Appodeal.NATIVE)
Appodeal.isLoaded(Appodeal.NATIVE);
To get how many NativeAd
instances are loaded, use the method:
- Kotlin
- Java
val nativeAmount = Appodeal.getAvailableNativeAdsCount()
int nativeAmount = Appodeal.getAvailableNativeAdsCount();
By default, the Appodeal SDK with AutoCahce enabled loads 2 instances of NativeAd
each
We recommend you always check whether an ad is available before trying to show it.
Get Loaded Native Ads
To get loaded native ads, use the following method:
- Kotlin
- Java
val nativeAds: List<NativeAd> = Appodeal.getNativeAds(amount)
List<NativeAd> nativeAds = Appodeal.getNativeAds(int amount);
Once you get the ads, they are removed from our SDK cache.
Display
To display NativeAd
, you need to call the following code:
- Kotlin
- Java
NativeAdView.registerView(nativeAd: NativeAd)
NativeAdView.registerView(NativeAd nativeAd);
SDK can't show ads without a network connection!
NativeAdView.registerView()
returns a boolean value indicating whether the show
method call was passed to the appropriate SDK.
Before the registerView(nativeAd)
method is called, NativeAdView
is in the visibility == GONE
state. After the call, the state will automatically change to visibility == VISIBLE
.
You don't need to change the visibility state, Appodeal SDK does it automatically.
After calling destroy()
, the state will automatically change to visibility == GONE
.
NativeAdView
and its successors have a built-in attribute tools:visibility="visible"
so the view
will be displayed in your IDE markup during development.
Placements
Appodeal SDK allows you to tag each impression with different placement. To use placements, you need to create placements in Appodeal Dashboard. Read more about placements.
To show an ad with placement, you have to call show method:
- Kotlin
- Java
NativeAdView.registerView(nativeAd: NativeAd, yourPlacementName: String)
NativeAdView.registerView(NativeAd nativeAd, String yourPlacementName)
If the loaded ad can’t be shown for a specific placement, nothing will be shown.
If auto caching is enabled, sdk will start to cache another ad, which can affect display rate. To save the loaded ad for future use (for instance, for another placement) check if the ad can be shown before calling the show method:
- Kotlin
- Java
if (NativeAd.canShow(context: Context, yourPlacementName: String)) {
NativeAdView.registerView(nativeAd: NativeAd, yourPlacementName: String)
}
if (NativeAd.canShow(Context context, String yourPlacementName)) {
NativeAdView.registerView(NativeAd nativeAd, String yourPlacementName)
}
You can configure your impression logic for each placement.
If you have no placements, or call NativeAdView.registerView
with a placement that does not exist,
the impression will be tagged with 'default' placement and its settings will be applied.
Placement settings affect ONLY ad presentation, not loading or caching.
UnregisterView
To unregister the view from displaying the currently registered native ad use the method:
- Kotlin
- Java
NativeAdView.unregisterView()
NativeAdView.unregisterView();
UnregisterView
method does not hide the NativeAdView
. It suspends the NativeAd display
tracking.
UnregisterView
makes sense to use, for example, if the NativeAdView is out of the screen while
scrolling in the list, or is temporarily overlapped by another View
/Fragment
/Activity
Destroy
To destroy the native ad view and perform any necessary cleanup, and hide NativeAdView
use the
method:
- Kotlin
- Java
NativeAdView.destroy()
NativeAdView.destroy();
This method should be called when the native ad is no longer needed.
Also, when destroy()
is called, the unregisterView
logic is triggered.
Common Mistakes
- No adAttributionView
The majority of ad networks require publishers to add a special mark to a native ad, so users don’t mistake them for content. That’s why you always need to make sure, that native ads in your app have the ad attribution (e.g., “Ad”) or the AdChoices icon.
- Absence of the required native ad elements
Every native ad should contain:
-
titleView TextView;
-
callToActionView Button;
-
adAttribution TextView;
-
NativeIconView
orNativeMedaiaView
. -
Native ad elements alteration
Advertisers expect that their ads will be displayed clearly and without any alteration. You can scale buttons and images, but you shouldn't crop, cover or distort them.
- Overlaying elements of native ads on each other
Make sure, that all elements of a native ad are visible and not overlaid.
Native ads requirements:
- All of the fields of native ad marked as mandatory must be displayed.
- Image assets can be resized to fit your ad space but should not be significantly distorted or cropped.
Check Viewability
You can always check in logs if show was tracked and your ad is visible.
You will see the Native [Notify Shown] log if show was tracked successfully.
- Log
Appodeal com.example.app D Native [Notify Shown]
You can use our demo app as a reference project.
Demo App
If you want to use advanced Native integration, you can find detailed documentation here