篩選
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
filters
查詢字串參數會限制傳回的資料
傳回的資料。使用 filters
參數時,
請提供做為篩選依據的維度,後面接著篩選器運算式。
查詢在經過篩選後,包含在結果中的資料列會受到限制。每一列
系統會根據篩選器測試結果中的資料列:如果篩選器達成比對,就會
保留該資料列,否則就會捨棄該資料列。
- 網址編碼:用戶端程式庫會自動編碼
篩選器運算子不過,如果您直接請求通訊協定
您必須按照下表指示,對篩選器運算子進行明確編碼。
- 篩選優先順序:篩選是在所有維度「之前」進行
而是匯總維度,因此傳回的指標
相關維度的數據
篩選器語法
單一篩選器會採用以下形式:
name operator expression
在這個語法中:
- name:做為篩選依據的維度名稱。
舉例來說,
AD_CLIENT_ID
會以廣告用戶端 ID 為篩選依據。
- operator — 定義要使用的篩選器比對類型。
- expression:指出包含在結果中的值。
涵蓋的所有維度
套用於報表的指標就能當做篩選器使用
但不含日期相關維度 (DATE
、WEEK
、
和 MONTH
)。如要按日期篩選,請指定
報表的日期範圍。
篩選器運算子
篩選器運算子有兩種。運算子必須經過網址編碼,才能
加進網址查詢字串中
運算子 |
說明 |
網址編碼表單 |
範例 |
== |
完全比對 |
%3D%3D |
匯總國家/地區名稱為「Canada」的指標:
filters=COUNTRY_NAME%3D%3DCanada |
=@ |
包含子字串 |
%3D@ |
彙整國家/地區名稱包含「United」的指標
比對美國和英國,例如:
filters=COUNTRY_NAME%3D@United |
篩選器運算式
篩選器運算式有幾個重要規則:
- 網址保留字元 —
&
必須以正常的方式進行網址編碼。用戶端程式庫
會為您處理這項工作,因此只有在符合下列條件的情況下,
才能直接呼叫通訊協定
- 保留字元 — 當逗號和反斜線出現在運算式時,
必須以反斜線逸出。
注意: 請務必正確加上反斜線,
避免重複逸出。
合併篩選器
篩選器可用 OR
和 AND
布林
邏輯。
OR 邏輯
OR
邏輯是使用,
篩選運算式。
範例: (每個都必須進行網址編碼)
國家/地區代碼為 (美國或英國):
COUNTRY_CODE==US,COUNTRY_CODE==UK
AND 邏輯
AND
邏輯是由提供多個篩選器參數的方式來完成。
會轉譯為在用戶端程式庫中提供篩選器陣列。
範例:
國家/地區代碼為 US AND 產品代碼為 AFC:
filters=COUNTRY_CODE%3D%3DUS&filters=PRODUCT_CODE%3D%3DAFC
合併 AND 和 OR 邏輯
可以將 AND 和 OR 邏輯合併為單一運算式。
注意: 系統會分別評估每個篩選器
,再將所有篩選器合併成一個 AND 邏輯運算式。
範例:
國家/地區代碼為 (US OR UK) AND 產品代碼為 AFC:
filters=COUNTRY_CODE%3D%3DUS,COUNTRY_CODE%3D%3DUK&filters=PRODUCT_CODE%3D%3DAFC
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eThe \u003ccode\u003efilters\u003c/code\u003e query string parameter limits the data returned in an AdSense Management API report, allowing you to filter by dimension using operators and expressions.\u003c/p\u003e\n"],["\u003cp\u003eFiltering happens before aggregation, ensuring metrics reflect only the relevant dimensions.\u003c/p\u003e\n"],["\u003cp\u003eFilter expressions use operators like \u003ccode\u003e==\u003c/code\u003e for exact match and \u003ccode\u003e=@\u003c/code\u003e for substring match, requiring URL encoding for direct protocol calls.\u003c/p\u003e\n"],["\u003cp\u003eFilters can be combined using comma (\u003ccode\u003e,\u003c/code\u003e) for \u003ccode\u003eOR\u003c/code\u003e logic within a single filter parameter and multiple filter parameters for \u003ccode\u003eAND\u003c/code\u003e logic.\u003c/p\u003e\n"],["\u003cp\u003eDate filtering is done by specifying the date range for the report instead of using date-related dimensions in the \u003ccode\u003efilters\u003c/code\u003e parameter.\u003c/p\u003e\n"]]],["The `filters` parameter in the AdSense Management API refines report data by specifying dimensions and filter expressions. Filtering happens before aggregation, ensuring metrics represent only relevant dimensions. Filters use the syntax `name operator expression`, with `==` for exact matches and `=@` for substring containment. Multiple filters can be combined using `OR` (commas within a filter) and `AND` (multiple filter parameters), allowing complex logic. Date-related dimensions cannot be used, but escaping rules must be followed.\n"],null,["# Filtering\n\nThe `filters` query string parameter restricts the data returned\nin an AdSense Management API report. When you use the `filters` parameter, you\nsupply a dimension you want to filter on, followed by the filter expression.\n\nFiltered queries restrict the rows that get included in the result. Each row\nin the result is tested against the filter: if the filter matches, the row is\nretained and if it doesn't match, the row is dropped.\n\n- **URL Encoding**: The client libraries automatically encode the filter operators. However, if you make requests directly to the protocol, you must explicitly encode filter operators as indicated in the table below.\n- **Filtering priority** : Filtering occurs *before* any dimensions are aggregated, so that the returned metrics represent the total for only the relevant dimensions.\n\nFilter Syntax\n-------------\n\nA single filter uses the form: \n\n```\nname operator expression\n```\n\nIn this syntax:\n\n- *name* --- the name of the dimension on which to filter. For example: `AD_CLIENT_ID` will filter on the ad client ID.\n- *operator* --- defines the type of filter match to use.\n- *expression* --- states the values included in the results.\n\nAll [dimensions](/adsense/management/metrics-dimensions) that\napply to the metrics being reported on can be used as filters, with the\nexception of the date-related dimensions (`DATE`, `WEEK`,\nand `MONTH`). To filter by date, [specify the\ndate range for the report](/adsense/management/reporting/date_ranges) instead.\n\nFilter Operators\n----------------\n\nThere are two filter operators. The operators must be URL encoded in order to\nbe included in URL query strings.\n\n\u003cbr /\u003e\n\n| Operator | Description | URL Encoded Form | Example |\n|----------|--------------------|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `==` | Exact match | `%3D%3D` | Aggregate metrics where the country name is *Canada* : `filters=COUNTRY_NAME%3D%3DCanada` |\n| `=@` | Contains substring | `%3D@` | Aggregate metrics where the country name contains *United* , this matches United States and United Kingdom for example: `filters=COUNTRY_NAME%3D@United` |\n\n\u003cbr /\u003e\n\nFilter Expressions\n------------------\n\nThere are a couple of important rules for filter expressions:\n\n- **URL-reserved characters** --- Characters such as `&` must be url-encoded in the usual way. Client libraries take care of this for you, so you only have to worry about this encoding if you are making direct calls to the protocol.\n- **Reserved characters** --- The comma and backslash must be backslash escaped when they appear in an expression.\n - backslash `\\\\`\n - comma `\\,`\n\n**Note:**Make sure you escape backslashes before\ncommas, in order to avoid double escaping.\n\nCombining Filters\n-----------------\n\nFilters can be combined using `OR` and `AND` boolean\nlogic.\n\n### OR logic\n\n`OR` logic is defined using a comma (`,`) inside the\nfilter expression. \n**Example:** *(each must be URL encoded)*\n\n\nCountry code is either (US OR UK): \n\n`COUNTRY_CODE==US,COUNTRY_CODE==UK`\n\n### AND logic\n\n`AND` logic is achieved by providing multiple filter parameters,\nwhich translates into providing an array of filters in the client libraries. \n**Example:**\n\nCountry code is US AND product code is AFC: \n\n`filters=COUNTRY_CODE%3D%3DUS&filters=PRODUCT_CODE%3D%3DAFC`\n\n### Combining AND and OR logic\n\nIt's possible to combine AND and OR logic into a single expression.\n\n**Note:**Each filter is evaluated individually\nbefore all filters are combined into an AND logical expression. \n**Example:**\n\nCountry code is (US OR UK) AND product code is AFC: \n\n`filters=COUNTRY_CODE%3D%3DUS,COUNTRY_CODE%3D%3DUK&filters=PRODUCT_CODE%3D%3DAFC`\n\nNext steps\n----------\n\n- [Choosing the Right Dimension](/adsense/management/reporting/right_dimension)\n- [Running Large Reports](/adsense/management/reporting/large_reports)\n- [List of Metrics and Dimensions](/adsense/management/metrics-dimensions)"]]