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.
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
- Log in to https://app.mopub.com and click on the Inventory Tab. Then click on the Add a New App button.
- Fill in the fields with your app info (e.g., platform, app name, package name, category, etc.)
- When you’re done filling in the information, click the Save and View Code Integration button.
- You’ll be redirected to the Integration page, where your new Ad Unit ID will be generated.
- Copy your new Ad Unit ID and click on the All Done! button.
Create the Custom Event
- Click on the Networks tab at the top of the page.
- Click the drop-down Add a Network menu and select Custom Native Network.
- Enter the name of your Custom Native Network (e.g., Smaato SDK).
- Then select the App Targeting area and add the class name by selecting Set App Class.
- You’ll need to fill in the form with your class package:
- Enter the following in the Custom Event Class field:
com.smaato.soma.mopubcustomevent.SomaMopubAdapter
- 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)
- Click on Save Section, and you’re good on the Mopub side of things for now.
- Enter the following in the Custom Event Class field:
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 foronBannerLoaded(View)
andonBannerFailed(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
- Set up a MoPub native ad unit.
- Create a Custom Native Network on MoPub dashboard (or use your existing one from the previous steps).
- 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. - 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
- Add the Mopub SDK and display a native ad unit (according to Mopub’s setup instructions).
- Add the Smaato Android SDK into the project.
- Add the
SomaMopubNativeCustomEvent
file and place it inside the packagecom.smaato.soma.mopubcustomevent
in your app. - 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:
- Create a Custom Native Network on MoPub dashboard (or use your existing one from the previous steps).
- Enter
com.smaato.soma.mopubcustomevent.SomaMopubAdapterInterstitial
in the field CUSTOM EVENT CLASS - 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
- Add the MoPub SDK and display an interstitial ad unit (according to MoPub’s setup instructions).
- Add the Smaato Android SDK into the project.
- Add the
SomaMopubAdapterInterstitial.java
file and place inside the packagecom.smaato.soma.mopubcustomevent
in your App. - 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:
- Create a Custom Native Network on MoPub dashboard (or use your existing one from the previous steps).
- Enter
com.smaato.soma.mopubcustomevent.SomaMopubRewardedVideoAdapter
in the field for CUSTOM EVENT CLASS. - 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
- Add the Mopub SDK and display a rewarded video ad unit (according to Mopub’s setup instructions).
- Add the Smaato Android SDK into the project.
- Add the
SomaMopubRewardedVideoAdapter.java
file and place inside the packagecom.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:
- Create a Custom Native Network on MoPub dashboard (or use your existing one from the previous steps).
- Enter
com.smaato.soma.mopubcustomevent.SomaMopubVideoAdapter
in the field for Custom Event Class. - 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
- Add the Mopub SDK and display an interstitial ad unit (according to Mopub’s setup instructions).
- Add the Smaato Android SDK into the project.
- Add the
SomaMopubVideoAdapter.java
file and place inside the packagecom.smaato.soma.mopubcustomevent
in your App.
Edit SomaMopubVideoAdapter.java
class if you need any customization.
Last Modified: September 24, 2019 at 8:59 pm
© 2005-2020 Smaato, Inc. All Rights Reserved. Smaato® is a registered trademark of Smaato, Inc.