應用程式初始化時,若刊登序列中介服務鏈太長,且包含多個第三方轉接程式,廣告請求延遲時間可能會增加,影響到重要曝光 (使用者工作階段中最先放送的廣告曝光)。當廣告請求尚未回傳回應,首次曝光延遲時間增加,可能會使廣告無法放送。
本指南涵蓋下列主題,有助於減少應用程式工作階段的首次曝光延遲:
事前準備
請先設定 Google Mobile Ads SDK,再繼續操作。
設定初始化逾時
為避免錯失曝光商機,請設定初始化逾時。這樣做可避免應用程式超出您定義的時間限制。您可以在設定的時間限制過後或初始化完成後,再提出廣告請求。
以下範例將初始化逾時設為五秒:
Swift
Task {
// Create TaskGroup to manage a race between
// SDK initialization and a 5 second timer.
await withTaskGroup(of: Void.self) { group in
// Create a task to initialize the MobileAds SDK.
group.addTask {
await withCheckedContinuation { continuation in
MobileAds.shared.start { _ in
// SDK initialization finished, resume the continuation.
// This will not stop the SDK's internal initialization process.
continuation.resume()
}
}
}
// Create a cancellable task which is a 5 second timer.
group.addTask {
do {
// Sleep for 5 seconds. This delay *is* cancellable.
try await Task.sleep(nanoseconds: 5 * 1_000_000_000)
} catch {
// cancelAll() will stop this task and throw CancellationError.
// This happens if the SDK initialization completes first.
}
}
// Wait for either task to complete.
await group.next()
// Cancel the timer task if the SDK initialized first.
group.cancelAll()
}
// Load an ad once after task group finishes.
await self.loadAd()
將刊登序列廣告來源從第一個請求中移除
如不希望放送廣告時刊登序列廣告來源有額外延遲,請導入鍵/值區隔,將刊登序列廣告來源從第一個廣告請求移除。操作步驟如下:
- 建立中介服務群組,並新增出價廣告來源。
- 使用鍵「
latency」和值「low」,將鍵/值區隔加進新的僅出價中介服務群組。 - 在使用者介面中設定,讓新的「僅出價中介服務群組」優先順序高於主要中介服務群組。變更中介服務群組優先順序,就能調整次序。
在第一個廣告請求中,加入自訂指定目標鍵/值組合:
Swift
let customTargeting: [String: String] = ["latency": "low"] let request = GADRequest() request.customTargeting = customTargetingObjective-C
NSDictionary *customTargeting = @{@"latency" : @"low"}; GADRequest *request = [GADRequest request]; request.customTargeting = customTargeting;測試鍵/值區隔設定,確認您已正確指定新的僅出價中介服務群組。
提升較不要求時效的廣告曝光成效
如要提升較不要求時效的廣告曝光 (例如不需要在應用程式啟動時立即顯示的廣告) 成效,請使用廣告預先載入功能,並發出未指定僅出價中介服務群組的廣告請求。