批次
有時您無法透過單一報表取得所有必要資訊,例如在維度和指標不相容時,或是您想以不同方式彙整資料。
在這種情況下,您必須執行多份報表。
此外,批次處理是提升應用程式效能的有效方式,可減少要求數量。
提出多個獨立請求的問題
雖然這是簡單的解決方案,但在短時間內提出多個 API 要求,可能會導致您達到配額上限。
更好的做法是避免同時發出並行要求,而是改為建立批次要求。
報表批次處理
以使用者導向應用程式的例子來說,第一種方法是盡可能將多個獨立請求合併成單一批次要求。
報表 1:8 月前 10 名國家/地區
報表 2:同一個前 10 個國家/地區在 7 月的值,進行比較
報表 3:8 月的前 10 名管道
報表 4:相同 10 個管道在 7 月的值,用於比較
在上述範例中,報表 1 和 3 各自獨立,但由於提供的資料細分方式不同,因此無法合併成單一報表。不過,這些內容也可以透過批次處理。
我們需要在取得第一個批次的結果後執行報表 2 和 4,因為需要在請求中設定適當的篩選器。在第一個收到的結果後,可以做為第二個批次執行。
另一種方式是允許所有請求將一個批次合併成一個批次,您可以只傳回 7 月的所有值 (而不是只傳回前 10 名),甚至還有 8 月。根據相關 AdSense 帳戶大小以及應用程式可用的記憶體容量,這可能會是合理的選項。
進行方式
每個用戶端程式庫的批次作業處理方式皆不同,建議您參閱相關說明文件來瞭解詳情。以下提供幾個用戶端程式庫中相關說明文件的連結:
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-08-22 (世界標準時間)。
[null,null,["上次更新時間:2024-08-22 (世界標準時間)。"],[[["Batching requests improves app performance by reducing the number of API calls and mitigating quota limitations."],["Independent reports, like those with incompatible dimensions or metrics, can be combined into batch requests."],["Batching can involve grouping related reports or retrieving broader data sets to minimize the total number of batches."],["Specific batching implementations vary by client library (.NET, PHP, Python, Java, Ruby, etc.)."],["For handling very large reports or incompatible dimensions and metrics, refer to the provided resources for further guidance."]]],["When single reports can't provide all necessary data due to incompatible dimensions or different aggregation needs, multiple reports are required. Batching multiple API requests improves app performance and reduces quota limitations, avoiding parallel requests. Independent requests, like retrieving top countries and channels, can be combined into a single batch. Subsequent requests for comparison data can be batched afterward, once the initial batch results are available. Client libraries offer varied methods for batching, requiring consultation of their respective documentation.\n"]]