Skip to end of metadata
Go to start of metadata

Mediate with Android

Android Studio and Gradle

These instructions assume you are using Android Studio and Gradle. Most of the required AndroidManifest.xml entries (except the Location permissions) and ProGuard changes are automatically added to your app. If you are using other build systems, the steps may vary.

Mediation lets you sell ad impressions through multiple networks to generate more revenue. This is initiated by your main (mediating) SDK which calls out to one or more mediated SDKs in a "waterfall"-like process. If your main SDK can't show an ad for some reason, it can iterate over the list of mediated SDKs and contact them in the order you specify. This will continue until the impression is filled or you've run out of mediated SDKs.

Reasons to mediate to another SDK include the following:

  • To provide better monetization under specific circumstances

  • To provide access to information such as a unique user ID or the device's operating system, location, or ID

  • Some networks only accept requests from their own SDKs, forcing you to use their SDK to access their demand

This page describes how to set up mediation from an engineering perspective. For more information about how SDK mediation works at a high level, including ad ops information, see SDK Mediation.

Mediation in Closed Beta

Mediation is currently in a closed Beta and is not available to all clients. For more information about our mediation capabilities, contact your AppNexus representative.

On This Page

Let us mediate other networks

Supported Networks and Media Types

This section lists the networks that we support with mediation adaptors, as well as the media types that each adaptor supports. For each adaptor, we show whether the adaptor supports banners, interstitials, native, or all three.

AdaptorBannerInterstitialNativeDocs
AdMob and DFPYesYesYesGoogle Mobile Ads - Android Mediation
AmazonYesYesNoAmazon Mobile Ads for Android
FacebookYesYesYesFacebook Android SDK Documentation
InMobiYesYesYesInMobi Android SDK Documentation
MillennialYesYesNoMillennial Android SDK Documentation
MoPubYesYesYesMoPub Android SDK Documentation
SmartAdServerYesYesNoSmartAdServer SDK Documentation

Maven Settings

To mediate these networks, you'll need a supported release of our SDK, and a mediation adaptor that allows our SDK to communicate with the network's SDK. The easiest way to get the SDK and adaptors is to use Maven from your build.gradle as shown in the example below. The first block includes the dependencies for the SDK itself. The second block lists adaptors to mediate other SDKs. (Note that these are top-level blocks, not part of the buildscript block.) You can include or exclude any of the adaptors in the second block. Including an adaptor causes it to automatically include the appropriate 3rd party SDK (which is downloaded from our CDN at Gradle sync time).

Finally, note that the [5,6) notation means that when your app is compiled, the latest version of the SDK in the 5.x series will be included. When we release a new version of the SDK, all that you'll have to do to get the new version is recompile your app.

 Click here to see the build.gradle

Do not modify the mediation adaptors' build.gradle files. This may break the build.

Network-Specific Setup

This section has information about how to set up other networks' SDKs for mediation, including code samples (when special setup is required) and links to that SDK's documentation.

AdMob

Lifecycle Callbacks Required

When mediating AdMob/DFP banners, you must add lifecycle callbacks to your code as described in the section Implementation Note: Forwarding Lifecycle Callbacks of Integrate the SDK, as we need to forward the lifecycle callbacks to the AdMob/DFP banner as required by them. For more information about activity lifecycles, see Managing the Activity Lifecycle in the Android docs.

Native Mediation

Starting with v5.1 of the SDK, the AdMob Native Mediation adapter code was modified support the Google UnifiedNativeAd.

The following are no longer relevant and have been removed:

AdMobNativeSettings.setEnableAppInstallAd();
AdMobNativeSettings.setEnableContentAd();

For native mediation, add initialization code as described here:

If you intend to use MediaView for displaying Images/Video, you need to enable MediaView before making an ad request. If you don't explicitly enable it, we download the images for you and MediaView will not fill the images automatically.

If the NativeAdResponse is from AdMob, create a View of type UnifiedNativeAdView.


Setting the Custom Keyword

For passing the content URL to the Google SDK, the contenturl needs to be passed as a custom keyword with the requester ad object (BannerAdView, InterstitialAdView, NativeAdRequest). The key to be used is content_url. Here is an example:

For more information about the Google SDK, see the Google Mobile Ads SDK .

Amazon

In order to mediate the Amazon SDK, you must set the Application Key. To set the Application Key, call the following method in the onCreate() of your activity:

For more information about the Amazon SDK, see the Amazon Mobile Ads docs .

Facebook

No special setup is required.

For more information about the Facebook SDK, see the Facebook SDK for Android.

InMobi

To use InMobi, call the following:

For more information about the InMobi SDK, see their Android SDK Integration Guide .

Millennial

To pass in the AOL Mobile Platform's site ID for mediation, use the following code:

The Millennial mediation will work without this site ID. It's only necessary if you are using the AOL Mobile Platform.

For more information about the Millennial Media SDK, see the Millennial Android SDK docs.

MoPub

No special setup is required.

For more information about the MoPub SDK, see the MoPub Android SDK.

SmartAdServer

No special setup is required.

For more information about the the SmartAdServer SDK, see their SDK documentation.

Interstitials

If you are using SmartAdServer interstitial, be aware that SASInterstitialView does not have loadAd() and showAd() methods corresponding to the AppNexus SDK's InterstitialAdView. SASInterstitialView has only the loadAd() method which does both loading and showing of ads just in one call.

To be consistent with the the AppNexus SDK's InterstitialAdView.loadAd() and InterstitialAdView.showAd() method call sequence we do not display the SASInterstitialView until InterstitialAdView.showAd() is called.

In other words, it's expected that your app should immediately call showAd() in InterstitialAdView.onAdLoaded(). If not, the SASInterstitialView won't be displayed.

Placement Setup

Interstitial Mediation

If you want to do interstitial mediation, you must make sure your placement is set up in Console with:

  • Size: 1x1
  • Media Type: Interstitial

For instructions on creating placements, see Create a Placement.

Interstitial Mediation plus RTB and/or Managed Demand

If you want to do interstitial mediation and accept RTB and/or managed demand through the same placement, you must make sure your placement is set up in Console with:

  • Size: 1x1
  • Media Type: Interstitial
  • Media Type: Banner

Then, for non-mediated demand, you must pass the actual sizes of the creatives in your ad calls using the promo_sizes placement tag parameter.

For instructions on passing custom interstitial sizes, see the Using Custom Interstitial Sizes.

Custom Mobile Networks

Console for Publishers has built-in support for a number of popular mobile ad networks. If you want to mediate a network it doesn't support, you'll need to:

Let other networks mediate us

Our SDK comes with built-in support for being mediated by AdMob or MoPub. In each case, this requires changing some settings in the AdMob and/or MoPub web UIs.

Note: these instructions may not reflect the latest changes in the AdMob and MoPub UIs. We will attempt to keep them in sync, but we can't guarantee it.

Mediate us with MoPub

This section describes how to mediate our SDK using MoPub. These instructions assume that:

Gradle integration is not supported

Our SDK and the MoPub adaptor must be downloaded from GitHub and included manually. It can be found in the mediation/mediating folder.

Step 1. Go into the MoPub UI and set up a Custom Native Network

See the instructions in the MoPub documentation for setting up a Custom Native Network.

Step 2. Configure your Custom Native Network to call our SDK

Once you've set up a Custom Native Network, you must associate it with your placement in our system. In the MoPub UI, go to the Network Detail screen and click the Edit Network button.

To get the MoPub SDK to call our SDK for mediation, click Edit Section and enter a Custom Event Class and Custom Event Class Data as follows:

  • Custom Event Class: Enter a class name from our SDK's MoPub mediation adaptor. Depending on whether you want to show banners or interstitials, enter:

  • com.appnexus.opensdk.MoPubMediationBanner

  • com.appnexus.opensdk.MoPubMediationInterstitial
  • Custom Event Class Data: Enter the JSON MoPub needs to get its SDK talking to ours.

Here's an example:

  { "id": "12345", "height": "50", "width": "320" } 

These refer to the placement ID from our system, and to the height and width of the ads that placement should be able to accept. Note that the values must be strings.

Step 3. Verify that the integration is working

Verify that the integration is working as follows:

  • Use the settings in the MoPub UI to allow only this placement to serve. In other words, this Custom Native Network should always "win" the auction.

  • Check the logs to make sure that the MoPub SDK is calling out to our SDK.

  • You may not see an ad, since PSAs are turned off by default. Turn on PSAs if you want to visually verify the ad load (in addition to seeing the call in the logs). For instructions on turning on PSAs, see Integrate with Android.

Mediate us with AdMob

This section describes how to mediate our SDK using AdMob. These instructions assume that you have our SDK installed.

Gradle integration is not supported

Our SDK and the AdMob adaptor must be downloaded from GitHub and included manually. It can be found in the mediation/mediating folder.

Step 1. Go into the AdMob UI and set up a Mediation Placement

See the instructions in the AdMob documentation for setting up a mediation placement.

Step 2. Configure your mediation placement with a Custom Event to call our SDK

Once you've set up a mediation placement, you must associate it with your placement in our system. In the AdMob UI, under Monetize, click the Edit mediation button to the right of your ad unit.

Click New ad network. Then, to get the AdMob SDK to call our SDK for mediation, click custom event and enter the following information:

  • Class Name: Enter a class name from our SDK's AdMob adaptor. Depending on whether you want to show banners or interstitials, enter:

    • com.appnexus.opensdk.AdMobMediationBanner

    • com.appnexus.opensdk.AdMobMediationInterstitial
  • Parameter: This is where you must enter the placement ID from our system, e.g., 123456. Note that you must enter the placement ID directly as an integer, not as a quoted string.

  • Label: This field is not used by our system.

Step 3. Verify that the integration is working

Verify that the integration is working as follows:

  • Use the settings in the AdMob UI to allow only this placement to serve. In other words, this Custom Event should always "win" the auction.

  • Check the logs to make sure that the AdMob SDK is calling out to our SDK.

  • You may not see an ad load, since PSAs are turned off by default. Turn on PSAs if you want to visually verify the ad load (in addition to seeing the call in the logs). For instructions on turning on PSAs, see Toggle PSAs.

Related Topics