Mediation

AdMob Mediation is a feature that lets you serve ads to your apps from multiple sources, including the AdMob Network, third-party ad networks, and AdMob campaigns. AdMob Mediation helps maximize your fill rate and increase your monetization by sending ad requests to multiple networks to ensure you find the best available network to serve ads. Case study.

This guide is your one-stop shop for integrating mediation into your AdMob app. It covers both bidding and waterfall integrations.

Prerequisites

  • For bidding: Google Mobile Ads SDK 18.3.0 or higher.

Initialize the Mobile Ads SDK

The quick start guide shows you how to initialize the Mobile Ads SDK. During that initialization call, mediation and bidding adapters also get initialized. It is important to wait for initialization to complete before you load ads in order to ensure full participation from every ad network on the first ad request.

The sample code below shows how you can check each adapter's initialization status prior to making an ad request.

Java

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.AdapterStatus;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
                Map<String, AdapterStatus> statusMap = initializationStatus.getAdapterStatusMap();
                for (String adapterClass : statusMap.keySet()) {
                    AdapterStatus status = statusMap.get(adapterClass);
                    Log.d("MyApp", String.format(
                            "Adapter name: %s, Description: %s, Latency: %d",
                            adapterClass, status.getDescription(), status.getLatency()));
                }

                // Start loading ads here...
            }
        });
    }
}

Kotlin

import com.google.android.gms.ads.MobileAds

MobileAds.initialize(this) { initializationStatus ->
  val statusMap =
    initializationStatus.adapterStatusMap
  for (adapterClass in statusMap.keys) {
    val status = statusMap[adapterClass]
    Log.d("MyApp", String.format(
      "Adapter name: %s, Description: %s, Latency: %d",
      adapterClass, status!!.description, status.latency))
  }

  // Start loading ads here...
}

Check which ad network adapter class loaded the ad

Here is some sample code that logs the ad network class name for a banner ad:

Java

public void onAdLoaded() {
  Log.d("Banner adapter class name: " + ad.getResponseInfo().getMediationAdapterClassName());
}

Kotlin

override fun onAdLoaded() {
  Log.d("Banner adapter class name:" + ad.responseInfo.mediationAdapterClassName)
}

Refer to the ResponseInfo documentation on getMediationAdapterClassName() for details about this method.

Initialize your ad object with an Activity instance

In the constructor for a new ad object (for example, 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.

Rewarded ads mediation

We recommend that you override all default reward values by setting reward values in the AdMob UI. To do this, select the Apply to all networks in Mediation groups box so that the reward is consistent across all networks. Some ad networks don't provide a reward value or type at all. By overriding the reward value, the reward is consistent no matter which ad network served the ad.

For more information on setting reward values in the AdMob UI, refer to create a rewarded ad unit.

Native ads mediation

The following are some best practices to consider when implementing native mediation.

Native ad presentation policy
Each ad network has its own policies. When using mediation, it's important to remember that your app still needs to abide by the policies of the mediated network that provided the ad.
Use loadAd() instead of loadAds()
The loadAds() method currently serves only Google ads. For mediated ads, use loadAd() instead.