Native Ads integration

Native ads let you easily monetize your app in a way that's consistent with its existing design. The Instal SDK execute the download and all the tracking automatically, you can just populate your layout with the information managed by the sdk.

Prerequisites

Before integrating native ads in your app, you’ll need to go through the steps in our Getting Started Guide to integrate the SDK into your project.

In order to display a native ads, you need to create a "Mobile Native" AdUnit. You can create a new one here.

Choosing mobile adunit dimension

Download and display a native ad

The Instal SDK provides a custom class, InstalNativeAd, that handles fetching native ads. In the Activity or in the Fragment in which you want to show the native ad, declare a InstalNativeAd instance variable:

private InstalNativeAd instalNativeAd;

In your Activity’s (or Fragment) onCreate() method, instantiate the InstalNativeAd using the context and the Ad Unit ID.

instalNativeAd = new InstalNativeAd(this, "YOUR_ADUNIT_ID");

When you want to show the ad you can invoke makeRequest method passing a listener that will be invoked when the ad is ready to be displayed:

instalNativeAd.makeRequest(new InstalNativeAdListener() {
    @Override public void onLoad(NativeResponse nativeResponse) {
        //...
    }

    @Override public void onFail(NativeErrorCode errorCode) {
        //...
    }
});

Lastly, remember to call destroy() on the native ad in your Activity or Fragment onDestroy method.

Layout population

You can use the following informations to populate ad layout:

  • title
  • promo text
  • call to action text
  • long text
  • icon url
  • rating (optional)
  • list of screenshots (optional)

You can populate ad layout in onLoad method, NativeResponse object contains all the informations:

progress.setVisibility(View.GONE);
adLayout.setVisibility(View.VISIBLE);

titleView.setText(nativeResponse.getTitle());
promoView.setText(nativeResponse.getPromoText());
callToActionView.setText(nativeResponse.getCallToAction());
Float rating = nativeResponse.getRating();
if (rating != null) {
    ratingBar.setVisibility(View.VISIBLE);
    ratingBar.setRating(rating);
} else {
    ratingBar.setVisibility(View.GONE);
}

The Instal SDK doesn't download and cache images, you can easily manage them using an external library. For example you can download the icon using Picasso:

Picasso.with(NativeActivity.this).load(nativeResponse.getIconImageUrl()).into(image);

In onLoad method you must invoke registerView to track the ad impression and set the click listener on the view:

nativeResponse.registerView(adLayout, new OnClickListener() {
    @Override public void onClick(View v) {
    }
}, callToActionView);

Method parameters:

  • view: layout that contains the ad
  • onClickListener: listener invoked when the user click on the a clickable view. This listener is not mandatory (you can use the overloaded method with two parameters);
  • clickableViews: varargs of views where the user can click to show the ad destination.

A complete Activity is available in sample app.