This guide is for publishers who want to use the Google Mobile Ads SDK to load and display ads from MoPub via mediation. It covers how to add MoPub to an ad unit's mediation configuration, how to set up Ad Network Optimization (ANO), and how to integrate the MoPub SDK and adapter into an Android app.
Supported ad formats and features
The AdMob mediation adapter for MoPub has the following capabilities:
Formats | |
---|---|
Banners | |
Interstitials | |
Rewarded Video | |
Rewarded Video (new APIs) | |
Native Advanced | |
Features | |
Smart banners | |
Ad Network Optimization (ANO) | |
Native Video |
Requirements
- Android SDK 4.4 (API level 19) or higher
- Latest Google Mobile Ads SDK
Step 1: Set up MoPub
First, sign up and log in to your MoPub UI. Navigate to the Apps page and click the Add a New App button.
Select Android as the Platform for your app, enter the App name and Package name of your app. Then select a primary and secondary category of your app from the provided list.
MoPub requires you to create your first ad unit before you can finish adding your app.
For additional instructions on creating an ad unit, select the tab corresponding to your preferred ad format.
Banner
Choose Tablet as the Device type. Choose a banner format that matches the ad size you're requesting in your app. Enter a Name for your ad unit.
The refresh rate is handled by the Google Mobile Ads SDK according to your refresh rate setting in the AdMob UI. So, we recommend using a high value for the Refresh Interval here (e.g. 1000 seconds).
Interstitial
Choose Tablet as the Device type. Choose Tablet Full Screen as the Format. Enter a Name for your ad unit. Choose the type of Layout to present the ad in.
Native
Choose Tablet as the Device type. Choose Native (Custom layout) as the Format. Enter a Name for your ad unit.
Click Save and View Code Integration to get your Ad Unit ID.
In addition to the Ad Unit ID, you'll also need to obtain your MoPub API Key and Inventory Report ID to set up your AdMob ad unit ID. To find your API Key and Inventory Report ID, navigate to the Reports page and click View API Access Details.
MoPub Marketplace
To get ads from MoPub, your account must be approved for MoPub Marketplace. During your initial account setup, you will be prompted to go through the process for Marketplace approval. Part of this process includes entering your payment information.
See the Marketplace setup guide for more details.
Step 2: Configure mediation settings for your AdMob ad unit
You need to add MoPub to the mediation configuration for your ad unit. First sign into your AdMob account.
Next, navigate to the Mediation tab. If you have an existing mediation group you'd like to modify, click the name of that mediation group to edit it, and skip ahead to Add MoPub as an ad source.
To create a new mediation group, select Create Mediation Group.
Enter your ad format and platform, then click Continue.
Give your mediation group a name, and select locations to target. Next, set the mediation group status to Enabled. Then click Add Ad Units, which will open up the ad unit selection overlay.
Associate this mediation group with your existing AdMob ad unit. Then click Done.
You should now see the ad units card populated with the ad units you selected.
Add MoPub as an ad source
In the Ad Sources card, select Add Ad Network. Then select MoPub.
Enable the Optimize switch. Enter the API Key and Inventory Report ID obtained in the previous section to set up ANO for MoPub. Then enter an eCPM value for MoPub and click Continue.
Next, enter the Ad Unit ID obtained in the previous section. Then click Done.
Finally, click Save.
Using rewarded video ads
In the settings for your rewarded video ad unit, provide values for the reward amount and reward type. Then, to ensure you provide the same reward to the user no matter which ad network is served, check the Apply to all networks in Mediation groups box.
If you don't apply this setting, the MoPub adapter passes back the reward specified in the MoPub dashboard.
For more information on setting reward values for AdMob ad units, see Create an ad unit.Step 3: Import the MoPub SDK and adapter
Android Studio integration (recommended)
Add the following Maven repository and the implementation dependencies with
the latest versions of the MoPub SDK and adapter to your app-level
build.gradle
file:
repositories { jcenter() } ... dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'com.google.android.gms:play-services-ads:19.6.0' implementation 'com.google.ads.mediation:mopub:5.15.0.1' } ...
Migrate project to AndroidX
The MoPub SDK depends on Android support libraries but the latest Google Mobile Ads SDK uses Jetpack libraries.
To ensure the MoPub SDK and the Google Mobile Ads SDK are compatible, create
a gradle.properties
file in the top-level of your project, and add the
following code:
android.useAndroidX=true
android.enableJetifier=true
This will rewrite the MoPub SDK binary to use use Jetpack libraries. See AndroidX migration guide for more information about these settings.
Manual integration
Download the latest version of the MoPub SDK's source from their GitHub repo and add it to your project.
Download the latest .aar file of the MoPub adapter from Bintray, located under the Files tab, and add it to your project.
Step 4: Additional code required
No Additional code required for MoPub integration.
Step 5: Test your implementation
To get test ads from MoPub, you need a guaranteed or backfill line item. MoPub recommends adding the Demo line item to your ad unit to get test ads. The Demo line item is added to your MoPub account by default.
The Demo Line Item contains test creatives for native and banner ad units by default, but does not have a test creative for interstitial ad units. To add your own test creative for interstitial ads, you need to upload a simple image to the MoPub UI by navigating to the Demo Line Item and clicking the Add a New Creative button. Choose Tablet Full Screen format. Fill the form with the necessary details and click Save to add your test creative to the Demo Line Item.
That's it! You now have a working mediation integration with MoPub.
Optional steps
EU Consent and GDPR
Under the Google EU User Consent Policy, you must ensure that certain disclosures are given to, and consents obtained from, users in the European Economic Area (EEA) regarding the use of device identifiers and personal data. This policy reflects the requirements of the EU ePrivacy Directive and the General Data Protection Regulation (GDPR). When seeking consent, you must identify each ad network in your mediation chain that may collect, receive, or use personal data and provide information about each network's use. Google currently is unable to pass the user's consent choice to such networks automatically.
To collect consent for MoPub, MoPub asks that you use its consent mechanism. See the MoPub GDPR Publisher Integration Guide for more information.
Permissions
If the user's location needs to be used for the targeting, MoPub recommends
adding the following optional permission into your app's AndroidManifest.xml
file:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
MoPub recommends adding the following optional permission for MRAID 2.0:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Using native ads
Network-specific parameters
The MoPub adapter supports an additional request parameter which can be passed
to the adapter using the MoPubAdapter.BundleBuilder
class. This class includes
the following method:
setPrivacyIconSizeDp(int)
- Sets the privacy icon size in dp. Values can range from 10 to 30 inclusive. The default size for the privacy icon is 20 x 20 dp.
Here's a code example of how to set this ad request parameter:
JAVA
Bundle bundle = new MoPubAdapter.BundleBuilder() .setPrivacyIconSizeDp(15) .build(); AdRequest adRequest = new AdRequest.Builder() .addNetworkExtrasBundle(MoPubAdapter.class, bundle) .build();
KOTLIN
val bundle = MoPubAdapter.BundleBuilder() .setPrivacyIconSizeDp(15) .build() val adRequest = AdRequest.Builder() .addNetworkExtrasBundle(MoPubAdapter::class.java, bundle) .build()
Ad Rendering
The MoPub adapter returns its native ads as
UnifiedNativeAd
objects.
It populates the following
fields
for a
UnifiedNativeAd
.
Field | Populated by MoPub adapter |
---|---|
Headline | |
Image | |
Body | |
App icon | |
Call to action | |
Star rating | |
Store | |
Price |
Impression and Click Tracking
MoPub and Google Mobile Ads SDKs track impressions and clicks in their own way, so there may be discrepancies.
Error codes
If the adapter fails to receive an ad from MoPub,
publishers can check the underlying error from the ad response using
ResponseInfo.getAdapterResponse()
under the following classes:
com.google.ads.mediation.mopub.MoPubAdapter
com.google.ads.mediation.mopub.MoPubMediationAdapter
Here are the codes and accompanying messages thrown by the MoPub adapter when an ad fails to load:
Error code | Reason |
---|---|
101 | MoPub server parameters configured in the AdMob UI are missing/invalid. |
102 | The requested banner size does not map to a valid MoPub ad size. |
103 | Activity context is null. |
104 | Mopub SDK not initialized. |
105 | Wrong native ad type. |
107 | An ad is already loaded for this network configuration. |
108 | Ad expired. |
110 | Requires native ads. |
111 | Native ad is missing required assets. |
112 | Ad is not ready. |
0-99 | MoPub SDK error. See code for more details. |
1000-1099 | MoPub native ads error. See code for more details. |
Additional Resources
For more details on how to set up test ad units, consult MoPub's Testing pages.
MoPub Android Mediation Adapter Changelog
Version 5.15.0.1
- Removed support for the deprecated
NativeAppInstallAd
format. Apps should request for unified native ads. - Updated the minimum required Google Mobile Ads SDK version to 19.6.0.
Built and tested with:
- Google Mobile Ads SDK version 19.6.0.
- MoPub SDK version 5.15.0.
Version 5.15.0.0
- Verified compatibility with MoPub SDK 5.15.0.
- Updated the minimum required Google Mobile Ads SDK version to 19.5.0.
Built and tested with:
- Google Mobile Ads SDK version 19.5.0.
- MoPub SDK version 5.15.0.
Version 5.14.0.0
- Verified compatibility with MoPub SDK 5.14.0.
- Updated the minimum required Google Mobile Ads SDK version to 19.4.0.
Built and tested with:
- Google Mobile Ads SDK version 19.4.0.
- MoPub SDK version 5.14.0.
Version 5.13.1.0
- Verified compatibility with MoPub SDK 5.13.1.
- Updated the minimum required Google Mobile Ads SDK version to 19.2.0.
- Added a new extra to the
MoPubAdapter.BundleBuilder
class:setCustomRewardData()
- custom reward data for MoPub rewarded ads.
Built and tested with:
- Google Mobile Ads SDK version 19.2.0.
- MoPub SDK version 5.13.1.
Version 5.13.0.0
- Verified compatibility with MoPub SDK 5.13.0.
Built and tested with:
- Google Mobile Ads SDK version 19.1.0.
- MoPub SDK version 5.13.0.
Version 5.12.0.1
- Updated the minimum required Google Mobile Ads SDK version to 19.1.0.
- Further added descriptive error codes and reasons for adapter load failures.
Built and tested with:
- Google Mobile Ads SDK version 19.1.0.
- MoPub SDK version 5.12.0.
Version 5.12.0.0
- Verified compatibility with MoPub SDK 5.12.0.
- Updated the minimum required Google Mobile Ads SDK version to 19.0.1.
- Adjusted support for flexible banner ad sizes.
- Added new extras to the
MoPubAdapter.BundleBuilder
class:setMinimumBannerWidth()
- minimum ad width allowed for MoPub banner ads.setMinimumBannerHeight()
- minimum ad height allowed for MoPub banner ads.
Built and tested with:
- Google Mobile Ads SDK version 19.0.1.
- MoPub SDK version 5.12.0.
Version 5.11.1.1
- Added descriptive error codes and reasons for adapter load/show failures.
Built and tested with:
- Google Mobile Ads SDK version 18.3.0.
- MoPub SDK version 5.11.1.
Version 5.11.1.0
- Verified compatibility with MoPub SDK 5.11.1.
Built and tested with:
- Google Mobile Ads SDK version 18.3.0.
- MoPub SDK version 5.11.1.
Version 5.11.0.0
- Updated minimum Android SDK version to API 19.
- Verified compatibility with MoPub SDK 5.11.0.
Built and tested with:
- Google Mobile Ads SDK version 18.3.0.
- MoPub SDK version 5.11.0.
Version 5.10.0.0
- Verified compatibility with MoPub SDK 5.10.0.
- Updated the minimum required Google Mobile Ads SDK version to 18.3.0.
Built and tested with:
- Google Mobile Ads SDK version 18.3.0.
- MoPub SDK version 5.10.0.
Version 5.9.1.1
- Native ads now leverage the unified native ads mediation API.
Built and tested with:
- Google Mobile Ads SDK version 18.2.0.
- MoPub SDK version 5.9.1.
Version 5.9.1.0
- Verified compatibility with MoPub SDK 5.9.1.
- Updated the minimum required Google Mobile Ads SDK version to 18.2.0.
Version 5.8.0.0
- Verified compatibility with MoPub SDK 5.8.0.
- Updated the minimum required Google Mobile Ads SDK version to 18.1.1.
Version 5.7.1.1
- Fixed an issue with loading ads using an
Application
Context. - Migrated the adapter to AndroidX.
- Updated the minimum required Google Mobile Ads SDK version to 18.0.0.
Version 5.7.1.0
- Verified compatibility with MoPub SDK 5.7.1.
- Fixed a bug where adapter would not invoke rewarded ad events when the MoPub SDK was initialized before sending an Ad Request.
Version 5.7.0.0
- Verified compatibility with MoPub SDK 5.7.0.
Version 5.4.1.2
- Added support for flexible banner ad sizes.
- Updated adapter to support new open-beta Rewarded API.
- Updated the minimum required Google Mobile Ads SDK version to 17.2.0.
Version 5.4.1.1
- Added support for MoPub Rewarded Video Ads.
Version 5.4.1.0
- Verified compatibility with MoPub SDK 5.4.1.
Version 5.4.0.0
- Fixed a native ad crash for publishers importing MoPub's non-native modules.
- Verified compatibility with MoPub SDK 5.4.0.
Version 5.3.0.2
- Remove the check that prevents ad requests for native content ad.
Version 5.3.0.1
- Initialize MoPub and reattempt ad requests manually in the adapters for use cases that do not do so in the app.
Version 5.3.0.0
- Verified compatibility with MoPub SDK 5.3.0.
Version 5.2.0.1
- Updated the adapter to invoke 'onAdLeftApplication()' ad event.
Version 5.2.0.0
- Verified compatibility with MoPub SDK 5.2.0.
Version 5.1.0.0
- Verified compatibility with MoPub SDK 5.1.0.
Version 5.0.0.0
- Verified compatibility with MoPub SDK 5.0.0.
Version 4.20.0.0
- Verified compatibility with MoPub SDK 4.20.0.
Version 4.19.0.1
- Fixed an NPE issue when a null image URL is returned by MoPub.
Version 4.19.0.0
- Verified compatibility with MoPub SDK 4.19.0.
Version 4.18.0.0
- Verified compatibility with MoPub SDK 4.18.0.
- Updated the Adapter project for Android Studio 3.0 and Android API 26.
Version 4.17.0.0
- Using MoPub's impression and click reporting for native ads (AdMob and MoPub impression and click statistics will match up).
- Verified compatibility with MoPub SDK 4.17.0.
Version 4.16.1.0
- Verified compatibility with MoPub SDK 4.16.1.
Version 4.16.0.0
- Verified compatibility with MoPub SDK 4.16.0.
Version 4.15.0.0
- Verified compatibility with MoPub SDK 4.15.0.
Version 4.14.0.0
- Verified compatibility with MoPub SDK 4.14.0.
- Adapter shows a warning when the requested banner ad size does not match the ad size set in MoPub UI.
Version 4.13.0.0
- Verified compatibility with MoPub SDK 4.13.0.
Version 4.12.0.0
- Verified compatibility with MoPub SDK 4.12.0.
- Added support for MoPub native ads.
- Updated interstitial and banner ads per Google's latest mediation APIs.
Previous
- Support for MoPub banner and interstitial ads.