中介服務


使用 AdMob 中介服務,您就能在應用程式中 多個來源,包括 AdMob 聯播網、第三方廣告聯播網 AdMob 廣告活動。AdMob 中介服務會向多個聯播網送出廣告請求,以確保您透過最合適的聯播網放送廣告,進而提高您的廣告供應率和收益。個案研究

必要條件

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

第一次使用中介服務嗎?請參閱「AdMob 中介服務總覽」。

初始化 Mobile Ads SDK

快速入門指南會說明如何初始化 Mobile Ads 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 的值

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

以下程式碼範例會從 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 中介服務中使用的橫幅廣告單元,在所有第三方廣告聯播網 UI 中停用重新整理功能。如此可避免因 AdMob 而重複更新 ,將根據橫幅廣告單元的重新整理頻率,觸發重新整理。

後續步驟

Google Mobile Ads C++ SDK 可納入 中介服務。因此,其他設定 (包括安裝中介服務適配器) 是 Android 和 iOS 平台專屬。如需更多資訊,請參閱 Google Mobile Ads Android SDK 選擇聯播網指南Google Mobile Ads iOS SDK 選擇聯播網指南