Hide

Mediation: Publishers Get Started

Introduction

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.

Prerequisites

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'])

In Eclipse, include the JAR files in your project's libs folder. Right click on your project and select Properties. Then add all the JAR files to your Java Build Path.

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.

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()
    .setGender(PublisherAdRequest.GENDER_FEMALE)
    .setBirthday(new GregorianCalendar(1985, 1, 1).getTime())  // January 1, 1985
    .build();

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.

v1

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 com.google.ads.mediation.millennial.MillennialAdapterExtras
InMobi com.google.ads.mediation.inmobi.InMobiAdapterExtras

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:

import com.google.android.gms.ads.doubleclick.PublisherAdRequest;
import com.google.android.gms.ads.doubleclick.PublisherAdView;
import com.google.ads.mediation.inmobi.InMobiAdapterExtras;
import com.google.ads.mediation.millennial.MillennialAdapterExtras;

/* … */

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

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

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

    // Create the ad request with these extra parameters.
    PublisherAdRequest adRequest = new PublisherAdRequest.Builder()
        .addNetworkExtras(millennialExtras)
        .addNetworkExtras(inMobiExtras)
        .build();

    // Finally, request the ad.
    adView.loadAd(adRequest);
v2

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.

FAQ

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.

Send feedback about...

SDK for DFP Users on Android