Android SDK MoPub Adapter

68 views 19/01/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:

  • Integrate YouAppi SDK using YouAppi SDK integration document.
  • Add YouAppi MoPub mediation AAR file to your project.
  • Follow the instructions below.

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

  • Copy youappimopub.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 {
        compile(name:'youappimopub', ext:'aar')
    }
  • If you don’t use the MoPub full SDK in your project you’ll have to add these lines:
    compile('com.mopub:mopub-sdk-interstitial:4.11.0@aar') { transitive = true }
    compile('com.mopub:mopub-sdk-rewardedvideo:4.11.0@aar') { transitive = true }
  • Add YouAPPi as a third party custom native network to your MoPub account.
    Go to Networks -> Add a network -> Custom Native Network. In the “Set Up Your Inventory” section use the following Custom Event Classes:

    • For interstitial card ads use “Native” ad type with Custom Event Class “com.youappi.ai.mopub.YouAPPiInterstitialCard”.
    • For interstitial video ads use “Native” ad type with Custom Event Class “com.youappi.ai.mopub.YouAPPiInterstitialVideo”.
    • For rewarded video ads use “Rewarded Video” ad type with Custom Event Class “com.youappi.ai.mopub.YouAPPiRewardedVideo”
  • If you use proguard in your application you should add these entries to your proguard file:
    -keep class com.youappi.ai.mopub.YouAPPiInterstitialCard{*;}
    -keep class com.youappi.ai.mopub.YouAPPiInterstitialVideo{*;}
    -keep class com.youappi.ai.mopub.YouAPPiRewardedVideo{*;}
    -keep class com.youappi.ai.mopub.YouAPPiRewardedVideo$YouAPPiRewardedVideoListener{*;}
    -keep class com.youappi.ai.mopub.YouAPPiRewardedVideo$RewardedLifeCycleListener{*;}

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.mediation.mopub.YouAppiRewardedVideo
    • Interstitial Video: com.youappi.mediation.mopub.YouAppiInterstitialVideo
    • Interstitial Ad: com.youappi.mediation.mopub.YouAppiInterstitialCard

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

Initialize ad units

YouAPPi.init(this, "<Replace with YouAppi Token>");
MoPubInterstitial moPubInterstitial = new MoPubInterstitial(this, "<Replace with MoPob Interstitial Ad Unit ID>");
MoPubInterstitial moPubInterstitialVideo = new MoPubInterstitial(this, "<Replace with MoPob Interstitial Video Ad Unit ID>");
MoPubRewardedVideos.initializeRewardedVideo(this);

Rewarded Video

Load

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

Map localExtrasVideo = new HashMap<String, String>();
localExtrasVideo.put(YouAPPiInterstitialVideo.EXTRA_ADUNIT_ID, "InterstitalVideoUnitId");
moPubInterstitialVideo.setLocalExtras(localExtrasVideo);
moPubInterstitialVideo.load();

Show

moPubInterstitialVideo.show();

Interstitial Ad

Load

Map localExtrasCard = new HashMap<String, String>();
localExtrasCard.put(YouAPPiInterstitialCard.EXTRA_ADUNIT_ID, "InterstitialCardUnitId");
moPubInterstitial.setLocalExtras(localExtrasCard);
moPubInterstitial.load();

 Show

moPubInterstitial.show();