中介

借助 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 选择广告网络指南