中介服務


使用 AdMob 中介服務,您就能在應用程式中 多個來源,包括 AdMob 聯播網、第三方廣告聯播網 AdMob 廣告活動。AdMob 中介服務 可傳送廣告來提高您的供應率和收益 向多個網路發出要求,以找出最適合 放送廣告。 個案研究

必要條件

您必須先整合 導入應用程式後

第一次使用中介服務嗎?閱讀 AdMob 總覽 中介服務

初始化 Mobile Ads 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.
}

如要進一步瞭解如何使用 Futures,請參閱 使用 Future 監控方法的完成狀態 呼叫

查看 adNetworkClassName 的值

每則廣告結果都包含廣告聯播網類別名稱的相關資訊。 擷取目前廣告。

以下程式碼範例會從 AdResult 記錄廣告聯播網類別名稱 從 AdView 傳回。類似的程式碼可用於插頁式廣告 獎勵廣告:

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 Mobile Ads C++ SDK 可納入 中介服務。因此,進一步設定,包括安裝 中介服務轉接程式,僅適用於 Android 和 iOS 平台。如要 相關資訊,請參閱 Google Mobile Ads Android SDK 選擇聯播網 指南以及 Google Mobile Ads iOS SDK 選擇聯播網 指南