中介
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通过 AdMob 中介功能,您可以在您的应用中投放多个来源(包括 AdMob 广告联盟、第三方广告联盟和 AdMob 广告系列)的广告。AdMob 中介会将广告请求发送至多个广告联盟,以确保您找到最合适的广告联盟来投放广告,有助于最大限度提高您的填充率,增加您的收入。案例研究。
前提条件
在为广告格式集成中介功能之前,您需要将相应广告格式集成到自己的应用中:
中介功能新手一枚?阅读 AdMob 中介概览。
初始化移动广告 SDK
本快速入门指南介绍了如何初始化移动广告 SDK。在初始化调用期间,中介适配器也会初始化。请务必在初始化完成后再加载广告,以确保每个广告联盟都可完全参与第一个广告请求。
以下示例代码展示了如何在发出广告请求前检查每个适配器的初始化状态。
// 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.
}
如需详细了解如何使用 Future,请参阅使用 Future 监控方法调用的完成状态。
检查 adNetworkClassName
的值
每个广告结果都包含有关提取了当前广告的广告联盟的类名称的信息。
以下是一个示例代码,用于记录从 AdView
返回的 AdResult
中的广告联盟类名称。类似的代码可用于插页式广告和激励广告:
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.
}
对于 AdMob 中介里所使用的横幅广告单元,请确保停用所有第三方广告联盟界面中的刷新功能。这可防止重复刷新,因为 AdMob 还会根据横幅广告单元的刷新频率触发刷新。
后续步骤
Google 移动广告 C++ SDK 封装了用于中介的 Android 和 iOS SDK 实现。因此,进一步的配置(包括安装中介适配器)特定于 Android 和 iOS 平台。如需了解详情,请参阅 Google 移动广告 Android SDK 选择广告网络指南和 Google 移动广告 iOS SDK 选择广告网络指南。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Google Mobile Ads C++ SDK is deprecated and will be end-of-maintenance on June 17, 2025; developers should use the iOS and Android SDKs instead.\u003c/p\u003e\n"],["\u003cp\u003eAdMob Mediation allows you to serve ads from multiple sources, including AdMob Network, third-party ad networks, and AdMob campaigns to maximize your fill rate and increase monetization.\u003c/p\u003e\n"],["\u003cp\u003eBefore integrating mediation, you must integrate the desired ad format (Banner, Interstitial, or Rewarded) into your app.\u003c/p\u003e\n"],["\u003cp\u003eInitialize the Mobile Ads SDK to ensure mediation adapters are initialized and wait for initialization to complete before loading ads for full ad network participation.\u003c/p\u003e\n"],["\u003cp\u003eFurther configuration and installation of mediation adapters are platform-specific (Android and iOS), so refer to the respective platform guides for detailed instructions.\u003c/p\u003e\n"]]],["The Google Mobile Ads C++ SDK is deprecated as of June 17, 2024, with maintenance ending June 17, 2025; developers should use the iOS and Android AdMob SDKs instead. AdMob Mediation allows serving ads from multiple sources to maximize fill rate. Before using mediation, integrate the ad formats (banner, interstitial, rewarded). Initialization of the Mobile Ads SDK includes mediation adapters. Developers can check adapter status and monitor ad network class names. For banner ads, disable refresh in third-party networks to prevent double refreshes. Further mediation configuration requires per-platform setup for Android and iOS.\n"],null,["# Mediation\n\n| **DEPRECATED:** The Google Mobile Ads C++ SDK is *deprecated* as of June 17, 2024 and should not be adopted in projects that don't already use it. It will enter *End-of-Maintenance (EoM)* on June 17, 2025. Note that versions of the SDK released before the EoM date will continue to function, but no further bug fixes or changes will be released after the EoM date.\n|\n| Instead of the Google Mobile Ads C++ SDK, consider using the\n| [iOS](/admob/ios/quick-start) and\n| [Android](/admob/android/quick-start) SDKs from AdMob.\n| For support, reach out to the\n| [Google Mobile Ads SDK Technical Forum](https://groups.google.com/g/google-admob-ads-sdk).\n\n\u003cbr /\u003e\n\nAdMob Mediation is a feature that lets you serve ads to your apps from\nmultiple sources, including the AdMob Network, third-party ad networks, and\n[AdMob campaigns](//support.google.com/admob/answer/6162747). AdMob Mediation\nhelps maximize your fill rate and increase your monetization by sending ad\nrequests to multiple networks to ensure you find the best available network to\nserve ads.\n[Case study](//admob.google.com/home/resources/cookapps-grows-ad-revenue-86-times-with-admob-rewarded-ads-and-mediation/).\n\nPrerequisites\n-------------\n\nBefore you can integrate mediation for an ad format, you need to integrate that\nad format into your app:\n\n- [Banner](/admob/cpp/banner)\n- [Interstitial](/admob/cpp/interstitial)\n- [Rewarded](/admob/cpp/rewarded)\n\nNew to mediation? Read [Overview of AdMob\nmediation](//support.google.com/admob/answer/3063564).\n\nInitialize the Mobile Ads SDK\n-----------------------------\n\nThe quick start guide shows you how to [initialize the Mobile Ads\nSDK](/admob/cpp/quick-start#initialize_the_mobile_ads_sdk).\nDuring that initialization call, mediation adapters also get\ninitialized. It is important to wait for initialization to complete before you\nload ads in order to ensure full participation from every ad network on the\nfirst ad request.\n\nThe sample code below shows how you can check each adapter's initialization\nstatus prior to making an ad request. \n\n // Initialize the Google Mobile Ads library\n firebase::gma::Initialize(*app);\n\n // In a game loop, monitor the initialization status\n auto initialize_future = firebase::gma::InitializeLastResult();\n\n if (initialize_future.status() == firebase::kFutureStatusComplete &&\n initialize_future.error() == firebase::gma::kAdErrorCodeNone) {\n // Initialization completed successfully, log the adapter status:\n std::map\u003cstd::string, firebase::gma::AdapterStatus\u003e adapter_status_map =\n firebase::gma::GetInitializationStatus().GetAdapterStatusMap();\n\n for (auto it = adapter_status_map.begin(); it != adapter_status_map.end(); ++it) {\n std::string adapter_class_name = it-\u003efirst;\n firebase::gma::AdapterStatus adapter_status = it-\u003esecond;\n printf(\"adapter: %s \\t description: %s \\t is_initialized: %d latency: %d\\n\",\n adapter_class_name.c_str(),\n adapter_status.description().c_str(),\n adapter_status.is_initialized(),\n adpater_status.latency());\n }\n } else {\n // Handle initialization error.\n }\n\nFor more information about working with Futures, see\n[Use Futures to monitor the completion status of method\ncalls](/admob/cpp/quick-start#futures).\n\nCheck the value of `adNetworkClassName`\n---------------------------------------\n\nEach ad result contains information about the class name of the ad network that\nfetched the current ad.\n\nHere is a sample code that logs the ad network class name from an `AdResult`\nreturned from an `AdView`. Similar code can be used for interstitial and\nrewarded ads: \n\n firebase::Future\u003cAdResult\u003e load_ad_future = banner_view.loadAd(ad_request);\n\n // In a game loop, monitor the ad load status\n if (load_ad_future.status() == firebase::kFutureStatusComplete &&\n load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {\n const AdResult* ad_result = load_ad_future.result();\n printf(\"Loaded ad with adapter class name: %s\\n\",\n ad_result-\u003eadapter_class_name().c_str());\n } else {\n // Handle the load ad error.\n }\n\nBanner ads mediation\n--------------------\n\nMake sure to disable refresh in all third-party ad networks UI for banner ad\nunits used in AdMob Mediation. This will prevent a double refresh since AdMob\nalso triggers a refresh based on your banner ad unit's refresh rate.\n\nNext steps\n----------\n\nThe Google Mobile Ads C++ SDK wraps the Android and iOS SDK implementations for\nmediation. Therefore further configuration, including the installation of\nmediation adapters, is specific to the Android and iOS platforms. For more\ninformation, see the [Google Mobile Ads Android SDK Choose networks\nguide](/admob/android/choose-networks) and the [Google\nMobile Ads iOS SDK Choose networks\nguide](/admob/ios/choose-networks)."]]