This guide is intended for publishers that are interested in using Google Mobile Ads mediation. We'll walk through getting a mediation adapter set up with your current Android application and setting up additional request parameters.


Adding mediation adapters to your project

Include network adapters and SDKs

Once you know which networks you want to serve ads from, you can download the SDK and adapter for those networks from the mediation networks page. Some of these SDKs already include a Google Mobile Ads adapter.

In Android Studio, include the JAR files in your project's libs folder. Make sure that your build.gradle file includes

compile fileTree(dir: 'libs', include: ['*.jar'])

Configure the AndroidManifest.XML

Add entries to your AndroidManifest.xml as required by each ad network you intend to use. Instructions from each network can be found from the mediation networks page. Follow instructions related to modifying your AndroidManifest.xml file.

Your app won't need to call any ad network--the Google Mobile Ads SDK will call the 3rd party ad network adapters to fetch 3rd party ads on your behalf. If you don't wish to specify any additional request parameters, then you're done! Otherwise, read on to learn how to provide more information to the mediating ad networks.

Initialize your ad object with an Activity instance

In the constructor for a new ad object (e.g. AdView), you must pass in an object of type Context. This Context is passed on to other ad networks when using mediation. Some ad networks require a more restrictive Context that is of type Activity, and may not be able to serve ads without an Activity instance. Therefore, we recommend passing in an Activity instance when initializing ad objects to ensure a consistent experience with your mediated ad networks.

Child-directed treatment in mediation

DFP Mediation facilitates compliance with the Children's Online Privacy Protection Act (COPPA).

Set tagForChildDirectedTreatment(true) in the Google Mobile Ads SDK to indicate whether your content should be treated as child-directed for the purposes of COPPA. Google makes this signal available to third-party ad networks in Mediation to facilitate COPPA compliance. See Tag an ad request for child-directed treatment (TFCD) for more information.

DFP simply serves as a platform. The advertising relationship is between the mobile app developer and the third-party ad network, so it's the developer's responsibility to ensure that each third-party ad network serves ads that treat the developer's content as child-directed for purposes of COPPA.

Specify additional request parameters (Optional)

You can optionally add demographic targeting information such as user's gender and birthday to your PublisherAdRequest. These types of information can be used by networks to serve more finely targeted ads.

We provide methods for setting gender and birthday. These will be passed along to all networks that accept them. Here is an example:

PublisherAdRequest adRequest = new PublisherAdRequest.Builder()
    .setBirthday(new GregorianCalendar(1985, 1, 1).getTime())  // January 1, 1985

Some networks also support other request parameters that are specific to their network. Refer to the "v1" or "v2" instructions below to learn how to provide these other parameters to the networks. If you are unsure if the adapter is v1 or v2, try calling addNetworkExtrasBundle with the adapter class (as detailed in v2 below). If the adapter compiles, then it's a v2 adapter; otherwise, it's a v1 adapter. Note that you can use both v1 and v2 adapters in the same application.


You can pass extra parameters to specific mediation networks by using the addNetworkExtras() method of the PublisherAdRequest. The addNetworkExtras() method receives an instance of a class that implements NetworkExtras.

Each network defines its own extras class. The following table shows the names of these classes for some of the networks.

Ad Network Additional Parameters Class
Millennial Media

For example, both Millennial Media and InMobi allow specifying the income of the user to provide more relevant ads. In order to make the mediation framework pass an income when requesting an ad from these networks, you could use the following code:


/* … */

    /* Set parameters common to all networks in ad request. */

    // Millennial Media extra parameters.
    MillennialAdapterExtras millennialExtras = new MillennialAdapterExtras();

    // InMobi extra parameters.
    InMobiAdapterExtras inMobiExtras = new InMobiAdapterExtras();

    // Create the ad request with these extra parameters.
    PublisherAdRequest adRequest = new PublisherAdRequest.Builder()

    // Finally, request the ad.

You can pass extra parameters to specific mediation networks by using the addNetworkExtrasBundle() method on PublisherAdRequest.Builder. Pass the adapter class to which you want to send parameters, and a Bundle of values for the adapter to consume.

In most cases if an adapter supports extra parameters, it will have either constants to represent appropriate keys for the bundle, or have some method to help generate a valid bundle to pass to their network.


Do Ad Listeners still work with mediation?
Yes, they still work with all mediation networks.
Do v1 mediation adapters work with Google Play services?
Yes. The Mobile Ads SDK included in Google Play services is designed to maintain backwards compatibility with our v1 mediation adapters.
I want to add a new network to my mediation configuration for the next version of my app. How will that affect the current version of my app that doesn't include this network?
The SDK will detect that the adapter isn't there and fail gracefully; the request will go to the next network in the mediation waterfall.
What does the "Could not instantiate mediation adapter: x.y.z.SomeAdapter" error message mean?
Your project is likely missing the adapter library that contains this class. You need to include network adapters and SDKs for all ad networks you're mediating.

Send feedback about...

SDK for DFP Users on Android
Need help? Visit our support page.