MoPub Android SDK

This guide explains how to integrate Smaato third-party ads through the MoPub Mediation SDK for Android platforms.

We are currently compatible with MoPub Android Version 5.6.0 (as of March 18, 2019)

Initializing

All libraries need to be explicitly initialized. Please consult the MoPub integration guide.

Android Initialization

We also allow for usage through a MoPub account via custom events. Follow the instructions below.

Android Mediation Integration

For rewarded video ads in the MoPub SDK, please add the following code to your AndroidManifest file:

<activity
 android:name="com.mopub.mobileads.RewardedMraidActivity"
 android:configChanges="keyboardHidden|orientation|screenSize" />

MoPub Adapter Compatibility Matrix

Here you will find the ad format compatibility matrix for the MoPub and Smaato as a secondary setup.

MoPub SDK Version 4.7.0 Supported Ad format

Smaato SDK Version Banner Adapter Interstitial Adapter Native Adapter
v 6.1.1 and above Supported Supported not supported
v 6.0.0 Supported Supported not supported
v 5.1.2 Supported Supported Supported
v 5.1.1 Supported Supported Supported

MoPub SDK Version 4.12.0

Smaato SDK Version Banner Adapter Interstitial Adapter Native Adapter
v 6.1.1 and above Supported Supported Supported
v 6.0.0 Supported Supported Supported
v 5.1.2 not supported not supported not supported
v 5.1.1 not supported not supported not supported

MoPub SDK Version 4.13.0

Smaato SDK Version Banner Adapter Interstitial Adapter Native Adapter
v 6.1.1 and above Supported Supported Supported
v 6.0.0 Supported Supported Supported
v 5.1.2 not supported not supported not supported
v 5.1.1 not supported not supported not supported

MoPub SDK Version 4.15 and above

Smaato SDK Version Banner Adapter Interstitial Adapter Native Adapter Rewarded Adapter Interstitial Adapter
v 6.1.1 and above Supported Supported Supported Supported Supported
v 6.0.0 Supported Supported Supported not supported not supported
v 5.1.2 not supported not supported not supported not supported not supported
v 5.1.1 not supported not supported not supported not supported not supported

MoPub ID Configuration

Create a MoPub ID and Configure With the Smaato SDK

  1. Log in to https://app.mopub.com and click on the Inventory Tab. Then click on the Add a New App button.
  2. Fill in the fields with your app info (e.g., platform, app name, package name, category, etc.)
  3. When you’re done filling in the information, click the Save and View Code Integration button.
  4. You’ll be redirected to the Integration page, where your new Ad Unit ID will be generated.
  5. Copy your new Ad Unit ID and click on the All Done! button.

Create the Custom Event

  1. Click on the Networks tab at the top of the page.
  2. Click the drop-down Add a Network menu and select Custom Native Network.
  3. Enter the name of your Custom Native Network (e.g., Smaato SDK).
  4. Then select the App Targeting area and add the class name by selecting Set App Class.
  5. You’ll need to fill in the form with your class package:
    1. Enter the following in the Custom Event Class field: com.smaato.soma.mopubcustomevent.SomaMopubAdapter
    2. Also, put your Smaato Publisher ID and Adspace ID for the respective adspace in the Custom Event Class Data field, using JSON formatting – i.e. {"publisherId": "0","adSpaceId": "0"} (replace 0 with your IDs)
    3. Click on Save Section, and you’re good on the Mopub side of things for now.

Integrating Ad Formats

In this section, we will cover the ad format set up for the MoPub and Smaato as secondary.

Banner Ads

Requirements:

  • The latest Smaato SDK
  • The latest MoPub SDK
  • From version 6.0.0 onwards, the Smaato adapter implemented support for onBannerClicked() MoPub custom event. This addition also added support for onBannerLoaded(View) and onBannerFailed(MoPubErrorCode)

First, add the following permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Then declare the following MoPub and Smaato activities:

<!--Mopub -->
<activity android:name="com.mopub.mobileads.MoPubActivity"
 android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidActivity"
 android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.common.MoPubBrowser"
 android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity"
 android:configChanges="keyboardHidden|orientation|screenSize"/>
 
<!--Smaato-->
<activity android:name="com.smaato.soma.interstitial.InterstitialActivity" android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<activity android:name="com.smaato.soma.ExpandedBannerActivity" android:configChanges="keyboardHidden|orientation|screenSize">
</activity>

Next, in your “Activity,” add the following lines of code to your onCreate method:

MoPubView mAdView = (MoPubView) findViewById(R.id.adview);
mAdView.setAdUnitId("your_mo_pub_ad_unit_id"); // Enter your Ad Unit ID from www.mopub.com
mAdView.loadAd();

Then declare your view in your layout.xml by adding the following lines:

<com.mopub.mobileads.MoPubView
android:id="@+id/adview"
android:layout_width="fill_parent"
android:layout_height="50dp" />

Now add the SomaMopubAdapter.java class to the com.smaato.soma.mopubcustomevent package (i.e. copy paste the class included in the SDK download).

The following MoPub custom events are supported by Smaato’s Banner Adapter:

  • onBannerLoaded(View)
  • onBannerFailed(MoPubErrorCode)
  • onBannerClicked()

Native Ads

MoPub native ads can now be mediated to show Smaato ads by using custom event settings along with Smaato Adapters on the MoPub dashboard.

The following MoPub Custom Events are supported by Smaato’s Native Adapter:

  • notifyAdClicked
  • notifyAdImpressed
  • preCacheImages

Native Ads in the MoPub Dashboard

  1. Set up a MoPub native ad unit.
  2. Create a Custom Native Network on MoPub dashboard (or use your existing one from the previous steps).
  3. Enter com.smaato.soma.mopubcustomevent.SomaMopubNativeCustomEvent in the field CUSTOM EVENT CLASS. You can place or rename the adapter file as you wish in your project. Therefore you need to consider the new name or location when you setup the CUSTOM EVENT CLASS in MoPub dashboard.
  4. Enter {"publisherId": "0","adSpaceId": "3075"} in the CUSTOM EVENT CLASS DATA field. This will show a demo native ad from Smaato. So, please update it according to your publisher id and adspace id.

Native Ad Android App Setup – MoPub

  1. Add the Mopub SDK and display a native ad unit (according to Mopub’s setup instructions).
  2. Add the Smaato Android SDK into the project.
  3. Add the SomaMopubNativeCustomEvent file and place it inside the package com.smaato.soma.mopubcustomevent in your app.
  4. Edit the SomaMopubNativeCustomEvent class if you need any customization.

Interstitial Ads

The following MoPub Custom Events are supported by Smaato’s Interstitial Adapter:

  • showInterstitial()
  • onInterstitialLoaded()
  • onInterstitialFailed(MoPubErrorCode)
  • onInterstitialShown()
  • onInterstitialDismissed()
  • onInterstitialClicked()

Interstitial Ads Setup

For interstitial ads, the process is similar to banner and native ads:

  1. Create a Custom Native Network on MoPub dashboard (or use your existing one from the previous steps).
  2. Enter com.smaato.soma.mopubcustomevent.SomaMopubAdapterInterstitial in the field CUSTOM EVENT CLASS
  3. Enter {"publisherId": "0","adSpaceId": "0"} in the CUSTOM EVENT CLASS DATA field. This will show a demo Interstitial ad from Smaato. So, please update it according to your publisher id and adspace id.

Interstitial Ads Android App Setup

  1. Add the MoPub SDK and display an interstitial ad unit (according to MoPub’s setup instructions).
  2. Add the Smaato Android SDK into the project.
  3. Add the SomaMopubAdapterInterstitial.java file and place inside the package com.smaato.soma.mopubcustomevent in your App.
  4. Edit the SomaMopubAdapterInterstitial.java class if you need any customization.

Interstitial Ad Customization in MoPub

If you need any customization to decide on when to show the ad, update the listener methods as needed.

For example, if you would like to show SmaatoAd, only when calling MoPubInterstitial.show(), update the onReadyToShow() method as per the following code:

@Overridepublic void onReadyToShow() {
 
   new CrashReportTemplate<Void>() {
      @Override
      public Void process() throws Exception {
 
         mHandler.post(new Runnable() {
            @Override
            public void run() {
               customEventInterstitialListener.onInterstitialLoaded();
            }
         });
 
         return null;
      }
   }.execute();
 
}

Rewarded Video Ads

The following MoPub custom events are supported by Smaato’s Rewarded Video Adapter:

Callback Condition Notes
onRewardedVideoPlaybackError Video playback fails when trying to play it Error code MoPubErrorCode.INTERNAL_ERROR is used
onRewardedVideoStarted onRewardedVideoStarted SOMA SDK callback  
onRewardedVideoCompleted onRewardedVideoCompleted SOMA SDK callback A reward success is passed, using NO_REWARD_LABEL and DEFAULT_REWARD_AMOUNT
onRewardedVideoLoadSuccess onReadyToShow SOMA SDK callback  
onRewardedVideoClicked onWillOpenLandingPage SOMA SDK callback Only applies to end card clicks as reward videos are not clickable
onRewardedVideoClosed onWillClose SOMA SDK callback  
onRewardedVideoLoadFailure onFailedToLoadAd SOMA SDK callback Error code MoPubErrorCode.UNSPECIFIED is used

Rewarded Video With MoPub Callback

The Third Party Id is required for all MoPub callbacks is the SOMA Adspace ID.

For rewarded video ads, the process is similar to video and interstitial ads:

  1. Create a Custom Native Network on MoPub dashboard (or use your existing one from the previous steps).
  2. Enter com.smaato.soma.mopubcustomevent.SomaMopubRewardedVideoAdapter in the field for CUSTOM EVENT CLASS.
  3. Enter {"publisherId": "0","adSpaceId": "3090"} in the CUSTOM EVENT CLASS DATA field.
    • This will show a rewarded video demo ad from Smaato.
    • Please update this according to your Publisher ID and Adspace ID.

Rewarded Video Android App Setup

  1. Add the Mopub SDK and display a rewarded video ad unit (according to Mopub’s setup instructions).
  2. Add the Smaato Android SDK into the project.
  3. Add the SomaMopubRewardedVideoAdapter.java file and place inside the package com.smaato.soma.mopubcustomevent in your App.

Edit SomaMopubRewardedVideoAdapter.java class if you need any customisation.

Interstitial Video Ads

For video interstitial ads, the process is mostly similar to interstitial ads:

  1. Create a Custom Native Network on MoPub dashboard (or use your existing one from the previous steps).
  2. Enter com.smaato.soma.mopubcustomevent.SomaMopubVideoAdapter in the field for Custom Event Class.
  3. Enter {"publisherId": "0","adSpaceId": "3090"} in the Custom Event Class Data field.
    • This will show a demo video ad from Smaato.
    • Please update it according to your Publisher ID and Adspace ID.

Interstitial Video Ads Android App Setup – MoPub

  1. Add the Mopub SDK and display an interstitial ad unit (according to Mopub’s setup instructions).
  2. Add the Smaato Android SDK into the project.
  3. Add the SomaMopubVideoAdapter.java file and place inside the package com.smaato.soma.mopubcustomevent in your App.

Edit SomaMopubVideoAdapter.java class if you need any customization.

Modified: June 11, 2019 at 7:25 pm