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.
Prerequisites
Before you can integrate mediation for an ad format, you need to integrate that ad format into your app:
New to mediation? Read Overview of AdMob mediation.
Initialize the Mobile Ads SDK
The quick start guide shows you how to initialize the Mobile Ads SDK. During that initialization call, mediation 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.
// Initialize the Google Mobile Ads library
firebase::gma::Initialize(*app);
// In a game loop, monitor the initialization status
auto initialize_future = firebase::gma::InitializeLastResult();
if (initialize_future.status() == firebase::kFutureStatusComplete &&
initialize_future.error() == firebase::gma::kAdErrorCodeNone) {
// Initialization completed successfully, log the adapter status:
std::map<std::string, firebase::gma::AdapterStatus> adapter_status_map =
firebase::gma::GetInitializationStatus().GetAdapterStatusMap();
for (auto it = adapter_status_map.begin(); it != adapter_status_map.end(); ++it) {
std::string adapter_class_name = it->first;
firebase::gma::AdapterStatus adapter_status = it->second;
printf(“adapter: %s \t description: %s \t is_initialized: %d latency: %d\n”,
adapter_class_name.c_str(),
adapter_status.description().c_str(),
adapter_status.is_initialized(),
adpater_status.latency());
}
} else {
// Handle initialization error.
}
For more information about working with Futures, see Use Futures to monitor the completion status of method calls.
Check the value of adNetworkClassName
Each ad result contains information about the class name of the ad network that fetched the current ad.
Here is a sample code that logs the ad network class name from an AdResult
returned from an AdView
. Similar code can be used for interstitial and
rewarded ads:
firebase::Future<AdResult> load_ad_future = banner_view.loadAd(ad_request);
// In a game loop, monitor the ad load status
if (load_ad_future.status() == firebase::kFutureStatusComplete &&
load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
const AdResult* ad_result = load_ad_future.result();
printf(“Loaded ad with adapter class name: %s\n”,
ad_result->adapter_class_name().c_str());
} else {
// Handle the load ad error.
}
Banner ads mediation
Make sure to disable refresh in all third-party ad networks UI for banner ad units used in AdMob Mediation. This will prevent a double refresh since AdMob also triggers a refresh based on your banner ad unit's refresh rate.
Next steps
The Google Mobile Ads C++ SDK wraps the Android and iOS SDK implementations for mediation. Therefore further configuration, including the installation of mediation adapters, is specific to the Android and iOS platforms. For more information, see the Google Mobile Ads Android SDK Choose networks guide and the Google Mobile Ads iOS SDK Choose networks guide.