Mopub network mediation

If you already have the Mopub SDK integrated in your application code and you don't want to add more boilerplate code for ads the mediation publisher sdk allows you to integrate instal ads and networks into mopub without changing a single line of code.

Configuration

Gradle

In order to use the mopub's network mediation with instal you have to add the instal mediations sdk dependency to your project, and provide the mopub sdk and the instal publisher sdk dependencies in the gradle.build file.

The publisher sdk and the publisher-mediation sdk are hosted on bitbucket, so you'll need to add the repository to your gradle.build repositories as follows

repositories {
    // Other repositories
    maven { url 'https://bitbucket.org/tbdsrl/instal-publisher-sdk-releases/raw/master/' }
}

And then add the dependencies

    compile('com.mopub:mopub-sdk:4.9.0@aar') {
        transitive = true
    }

    compile 'com.instal:instal-publisher-sdk:1.0.24'

    compile 'com.instal:instal-publisher-sdk-mediations:0.0.1'

Mopub

So you have to configure your mopub adunits to support instal custom classes, using the networks panel edit or create an adunit (Banner, Intertitial or native), then provide the custom configuration as follows:

Ad Type Custom Event Method Custom Event Class Custom event class data
Banner empty com.mopub.nativeads.MopubInstalBanner {"ad_unit": "Your instal ad unit"}
Interstitial empty com.mopub.nativeads.MopubInstalInterstitial {"ad_unit": "Your instal ad unit"}
Native empty com.mopub.nativeads.MopubInstalNative {"ad_unit": "Your instal ad unit"}

Mopub configuration example:

Mopub adunit configuration

Requesting ads

We're done, when you execute an ad request trough mopub using the previously configured ad unit the mopub sdk will automatically instantiate and invoke the instal mediator sdk classes using the provided ad unit, mopub will also provide fallback ads if the third part network fails to load.

All following examples are provided by the https://www.mopub.com/resources/docs/ mopub docs

Request Interstitial

        MoPubInterstitial mInterstitial = new MoPubInterstitial(this, MOPUB_INTERSTITIAL_ADUNIT);
        mInterstitial.setInterstitialAdListener(this);
        mInterstitial.load();

Request Banner

Instal banner view will be automatically inserted into the MoPubAdView contained in your layout

        MoPubView moPubView = (MoPubView) findViewById(R.id.adview);
        moPubView.setAdUnitId(MOPUB_BANNER_ADUNIT);
        moPubView.loadAd();

Native ads

Mopub sdk will automatically fill the native ads fields (such as title,text,icon...) using your instal ad unit

Check mopub documentation for further details

Native ads in listview example:


  String[] testArray = {"1", "2", "3", "4"}; // Actual list view items

        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.base_row, R.id.testText, testArray); // List view adapter

        ViewBinder viewBinder = new ViewBinder // Mopub ad view binder
                .Builder(R.layout.native_layout)
                .iconImageId(R.id.native_ad_icon_image)
                .titleId(R.id.native_ad_title)
                .build();


        // Render and positioning rules
        MoPubNativeAdPositioning.MoPubServerPositioning adPositioning = MoPubNativeAdPositioning.serverPositioning();
        MoPubStaticNativeAdRenderer adRenderer = new MoPubStaticNativeAdRenderer(viewBinder);

        // Mopub list adapter wrapper
        MoPubAdAdapter mAdAdapter = new MoPubAdAdapter(this, adapter, adPositioning);
        mAdAdapter.registerAdRenderer(adRenderer);

        listView.setAdapter(mAdAdapter);


        // Native ad request
        RequestParameters.Builder myRequestParameters = new RequestParameters.Builder();

        myRequestParameters.desiredAssets(EnumSet.of(
                RequestParameters.NativeAdAsset.TITLE,
                RequestParameters.NativeAdAsset.TEXT,
                RequestParameters.NativeAdAsset.ICON_IMAGE,
                RequestParameters.NativeAdAsset.MAIN_IMAGE,
                RequestParameters.NativeAdAsset.CALL_TO_ACTION_TEXT));


        mAdAdapter.loadAds(MOPUB_NATIVE_ADUNIT, myRequestParameters.build());

Proguard

The following step is only necessary if you are using Proguard to obfuscate your code

-keep class com.mopub.nativeads.** { *; }
-dontwarn com.mopub.nativeads.**
-keepattributes *Annotation*,EnclosingMethod,Signature
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keep class com.instal.** { *; }
-dontwarn com.instal.**
-keepattributes *Annotation*,EnclosingMethod,Signature
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

Debugging

If everything has been configured correctly as ads are loaded you should see the following message in your android logcat :

instal.mediationapp I/InstalAd: Fetching ad for task #0
instal.mediationapp D/InstalAd: Loading custom event adapter.
instal.mediationapp D/InstalAd: adLoaded