Android SDK MoPub Adapter

177 views 06/05/2018 Shay Karpeles 0

Getting Started

This document details the process of integrating YouAppi’s SDK MoPub adapter with your Android app.

If you have any question you can email us to: sdk@youappi.com

The basic steps of integration are:

Download YouAppi’s Android SDK MoPub Adapter

Our Android SDK MoPub adapter can be downloaded as an AAR from the following URL: YouAppi Android SDK MoPub Adapter

Integration

Integrate using AAR files

  • Copy youappi-sdk-mopub.aar file to the apps/libs folder of your project.
  • Add the following to your project build.gradle file inside the repositories section:
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
  • Add the following under dependencies section of app’s build.gradle (replace the ‘x.xx’ version field with the latest available version of the SDK):
    dependencies {
        implementation name:'youappi-sdk-mopub', ext:'aar'
        implementation name:'youappi-android-sdk-moat', ext:'aar'
    }

Integrate using repository

  • Add the following repository to your project build.gradle:
repositories {
    maven { url "http://repository.youappi.com/repository/release" }
}
  • Add the following dependency to your module build.gradle:
dependencies {
    implementation "com.youappi.sdk:youappi-sdk-android-mopub-moat:4.0.4"
}

Proguard

If you use proguard in your application you should add these entries to your proguard file:

-keep class com.youappi.sdk.mediation.mopub.YouAPPiInterstitialAd{*;}
-keep class com.youappi.sdk.mediation.mopub.YouAPPiInterstitialVideo{*;}
-keep class com.youappi.sdk.mediation.mopub.YouAPPiRewardedVideo{*;}

Create YouAppi custom network

  • On MoPub platform on Networks tab, add a new custom 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.

Setup MoPub for YouAppi Ad units

Create rewarded video ad anit

  • On your MoPub account, press Apps tab.
  • Select your Android app for which you would like or create the new ad unit or create a new Android app.On your app screen press “New ad unit” button:

  • On your app screen press “New ad unit” button:

  • Name your add unit, select Format: Rewarded Video and press Save

Create Interstitial Video or Interstitial Ad units

  • Assuming you already created an Android app, press Apps tab and from the apps list choose your Android app.
  • Press New ad unit button to define a new ad unit for either Interstitial Video or Interstitial Ad.
  • Name you ad unit, choose relevant device and on format choose Fullscreen:

Setup Ad Unit on network

  • Choose Networks and select your YouAppi custom network.
  • On network details screen choose Edit Network.
  • On Set Up Your Inventory section, connect between your Android app ad unit and YouAppi by setting the proper Custom Event Class.
  • For each ad unit type there is a different custom event class:
    • Rewarded Video: com.youappi.sdk.mediation.mopub.YouAppiRewardedVideo
    • Interstitial Video: com.youappi.sdk.mediation.mopub.YouAppiInterstitialVideo
    • Interstitial Ad: com.youappi.sdk.mediation.mopub.YouAppiInterstitialAd
  • On the custom event class data the following information should be supplied:
    • accessToken – the access token of the partner received from YouAppi.
    • adUnitId – an arbitrary id chosen the by app developer to identify the ad unit id. It should be by only numbers, letters and underscores.
  • Here is an example of how the custom event class data should look like:
    {
      "accessToken": "821cfa77-3127-42b5-9e6b-0afcecf77c67",
      "adUnitId": "testRewardedVideoAdUnitId"
    }

Enable YouAppi ad unit to run on YouAppi custom network

  • Press Segments tab and choose your desired segment.
  • Under your Android app find your desired ad unit and YouAppi custom network.
  • Switch your network to running by pressing the button under Enabled column:

Use MoPub SDK to show YouAppi ad units

Rewarded Video

Load

MoPubRewardedVideos.initializeRewardedVideo(this);
MoPubRewardedVideos.loadRewardedVideo("<Replace with MoPob Rewarded Video Ad Unit ID>", new YouAPPiMediationSettings("RewardedAdUnitID"));

Show

MoPubRewardedVideos.showRewardedVideo("<Replace with MoPob Rewarded Video Ad Unit ID>");

Interstitial Video

Load

MoPubInterstitial moPubInterstitialVideo = new MoPubInterstitial(this, "<Replace with MoPob Interstitial Video Ad Unit ID>");
Map localExtrasVideo = new HashMap<String, String>();
localExtrasVideo.put(YouAPPiInterstitialVideo.EXTRA_ADUNIT_ID, "InterstitalVideoUnitId");
moPubInterstitialVideo.setLocalExtras(localExtrasVideo);
moPubInterstitialVideo.load();

Show

moPubInterstitialVideo.show();

Interstitial Ad

Load

MoPubInterstitial moPubInterstitial = new MoPubInterstitial(this, "<Replace with MoPob Interstitial Ad Unit ID>");
Map localExtrasCard = new HashMap<String, String>();
localExtrasCard.put(YouAPPiInterstitialCard.EXTRA_ADUNIT_ID, "InterstitialCardUnitId");
moPubInterstitial.setLocalExtras(localExtrasCard);
moPubInterstitial.load();

 Show

moPubInterstitial.show();

Demo App

A demo app showing a simple usage of the SDK can be found in the following bitbucket repository:

https://bitbucket.org/youappi/youappi-sdk-android-demo-simple

The demo app contains 3 modules:

  • app-demo – Shows how to use YouAppi’s SDK
  • app-demo-admob – Shows how to use YouAppi’s SDK with AdMob adapter
  • app-demo-mopub – Shows how to use YouAppi’s SDK with MoPub adapter

Please make sure to read the README.md file for further instructions.