Android MoPub SDK Native Ads Support

784 views 2018-04-15 Ofer Garnett 0

Introduction

The purpose of this to document is to describe the steps needed in order to add YouAppi native ads support via MoPub Android SDK.

Requirements

  • YouAppi’s Partner access token. The app access token is a unique identifier that is used by YouAppi to identify your app.
  • YouAppi-MoPub native ads JAR file. The JAR file is a Java piece of code allowing to show YouAppi’s demand using MoPub SDK.

Instructions

  • Put the JAR file under libs folder of your Android project.

  • On MoPub platform on Networks tab, add a new network for YouAppi:
  • On the popup that opens choose to add a Custom Native Network.
  • Name your new network (YouAppi might be a good name) and fill other relevant details.
  • On field CUSTOM EVENT CLASS enter the value: com.mopub.nativeads.YouAppiNative. It should look like:

 

  • Set your access token and ad unit id on field CUSTOM EVENT CLASS DATA. The value should look like: {“accessToken”: “e700f511-0e76-455c-bd0e-aaaaaaaaaaaa”, “adUnitId”: “your ad unit id”}. The access token is the partner access token you received from YouAppi. The ad unit id can be your MoPub ad unit ID or any other arbitrary name you would like to give to this placement.
  • Make sure to add YouAppi network as a source to your order/line item.

Adapter Events

If needed, it is possible to get events from the native ads adapter. Events are sent with the ad unit id.

Please avoid writing code that might take more than few milliseconds in these events.

The following events are supported:

  • onRequest – An ad was requested from YouAppi network.
  • onFilled – YouAppi network returned an ad.
  • onNoFilled – YouAppi network did not return an ad either because there was no fill or due to some error.
  • onImpression – Banner was shown on user’s device.
  • onClick – Banner was clicked.

Here is a usage example:

NativeAd.setNativeAdExtListener(new NativeAdExtListener() {
 
    @Override
    public void onRequest(final String adUnitId) {
        Log.i("", "REQUESTED: " + adUnitId);
    }
 
    @Override
    public void onFilled(final String adUnitId) {
        Log.i("", "FILLED: " + adUnitId);
    }
 
    @Override
    public void onNotFilled(final String adUnitId) {
        Log.i("", "NOT FILLED: " + adUnitId);
    }
 
    @Override
    public void onImpression(final String adUnitId) {
        Log.i("", "IMPRESSION: " + adUnitId);
    }
 
    @Override
    public void onClick(final String adUnitId) {
        Log.i("", "CLICK");
    }
});

Test

  • Load your app section that contains native ads and make sure you get native ads from YouAppi network.