Integrating MoPub with Mediation

This guide is intended 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 Automatic data collection, and how to integrate the MoPub SDK and adapter into an Android app.

Supported ad formats and features

The DFP mediation adapter for MoPub has the following capabilities:

Formats
Banners
Interstitials
Rewarded Video
Native Ad - Custom Rendering
Features
Smart banners
Automatic data collection
Native Video

Requirements

  • Android SDK 4.1 (API level 16) or higher
  • Google Play services 9.6.1 or higher

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.

MoPub new app

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 app

MoPub requires you to create your first Ad Unit before finishing 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 DFP 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 Fullscreen Tablet 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.

MoPub 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 DFP ad unit ID. To find your API Key and Inventory Report ID, navigate to the Reports page and click View API Access Details.

MoPub reporting keys

MoPub Marketplace

To get ads from MoPub, your account needs to 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.

MoPub marketplace

See the Marketplace setup guide for more details.

Step 2: Configure Mediation Settings for your DFP ad unit

Sign in to your DFP account. Navigate to Delivery > Yield Groups and click the Create Yield Group button.

DFP create yield group button

Enter a Yield Group Name, select your Ad Format, and set the Environment to Mobile App. Under the Targeting section, select the ad unit ID to which you want to add mediation.

Next, click the Add Another Yield Partner button.

If you already have a Yield Partner for MoPub, you can simply select it. Otherwise, select Create a new Yield Partner.

Select MoPub as the Yield partner and enter a unique Name. Check the checkbox for Enable automatic data collection of estimated CPM to optimize Mediation to enable automatic data collection, and enter the API Key and Inventory Report ID obtained in the previous section. Click Save when done.

Once the Yield partner is chosen, select Mobile SDK mediation as the Integration type and Android as the Operating system. Enter the Ad Unit ID obtained in the previous section. Enter a Default CPM value.

Click Save and Activate at the bottom of the page when done.

Step 3: Import the MoPub SDK and adapter

Add the following Maven repository and the implementation dependencies with the latest versions of the MoPub SDK and adapter in the app-level build.gradle file:

repositories {
    maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
}

...
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:xx.x.x'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
    implementation('com.mopub:mopub-sdk:5.0.0@aar') {
        transitive = true
    }
    implementation 'com.google.ads.mediation:mopub:5.0.0.0'
}
...

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

Modify Android manifest

Activities

Include the following Activity declarations in your AndroidManifest.xml under the application tag:

<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"/>

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

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.

MoPub demo item

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

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();
PublisherAdRequest adRequest = new PublisherAdRequest.Builder()
   .addNetworkExtrasBundle(MoPubAdapter.class, bundle)
   .build();

KOTLIN

val bundle = MoPubAdapter.BundleBuilder()
   .setPrivacyIconSizeDp(15)
   .build()
val adRequest = PublisherAdRequest.Builder()
   .addNetworkExtrasBundle(MoPubAdapter::class.java, bundle)
   .build()

Ad Rendering

The MoPub adapter returns its native ads as NativeAppInstallAd objects. It populates the following Native App install ad display fields for a NativeAppInstallAd :

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.

Additional Resources

For more details on how to set up test ad units, see MoPub's Testing Ads guide.

Send feedback about...

Google Mobile Ads SDK for DoubleClick for Publishers Android Apps
Need help? Visit our support page.