フィルタリング
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
filters
クエリ文字列パラメータは、返されるデータを制限します。
AdSense Management API レポートで
確認できますfilters
パラメータを使用すると、
フィルタを適用するディメンションに続けてフィルタ式を指定します。
フィルタされたクエリでは、結果に含まれる行が制限されます。各行
結果のフィルタがフィルタに対してテストされます。フィルタが一致する場合、その行は
一致しない場合、その行は削除されます。
- URL エンコード: クライアント ライブラリは、
フィルタ演算子を使用します。ただし、このプロトコルに直接リクエストを送信すると、
下の表に示すように、フィルタ演算子を明示的にエンコードする必要があります。
- フィルタの優先度: フィルタは特定のフィルタよりも前に行われます。
ディメンションは集計されるため、返される指標は
関連するディメンションのみを
ターゲティングできます
フィルタ構文
1 つのフィルタには次の形式を使用します。
name operator expression
この構文の説明は次のとおりです。
- name - フィルタを適用するディメンションの名前。
たとえば、「
AD_CLIENT_ID
」は広告クライアント ID でフィルタします。
- operator — 使用するフィルタの一致タイプを定義します。
- expression — 結果に含める値を記述します。
すべてのディメンション
フィルタとして使用でき、
日付関連のディメンション(DATE
、WEEK
、
および MONTH
)。日付でフィルタするには、
期間のみを使用できます。
フィルタ演算子
フィルタ演算子は 2 つあります。演算子を URL エンコードしないと、
URL クエリ文字列に含めることはできません。
演算子 |
説明 |
URL エンコード形式 |
例 |
== |
完全一致 |
%3D%3D |
国名が Canada の指標を集計する場合:
filters=COUNTRY_NAME%3D%3DCanada |
=@ |
文字列の一部に一致 |
%3D@ |
国名に United が含まれる指標を集計する場合、
United States と United States に一致します。たとえば、次のようになります。
filters=COUNTRY_NAME%3D@United |
フィルタ式
フィルタ式にはいくつか重要な規則があります。
- URL 予約文字 - 次のような文字
&
は、通常の方法で URL エンコードする必要があります。クライアント ライブラリ
自動的にエンコードされます。
プロトコルを直接呼び出します。
- 予約文字 - カンマとバックスラッシュを
式に含まれている場合は、バックスラッシュでエスケープされます。
注:
重複して使用しないでください。
フィルタの組み合わせ
フィルタは、ブール値 OR
と AND
を使用して組み合わせることができます。
できます。
OR 論理演算子
OR
論理は、,
フィルタ式を指定します。
例: (いずれも URL エンコードを使用)
国コードが US または UK のいずれかである:
COUNTRY_CODE==US,COUNTRY_CODE==UK
AND ロジック
AND
論理演算を行うには、複数のフィルタ パラメータを指定します。
これは、クライアント ライブラリでフィルタの配列を指定することになります。
例:
国コードが US で、かつ商品コードが AFC の場合:
filters=COUNTRY_CODE%3D%3DUS&filters=PRODUCT_CODE%3D%3DAFC
AND 論理演算子と OR 論理演算子の組み合わせ
AND 論理演算と OR 論理演算を 1 つの式にまとめることができます。
注: 各フィルタは個別に評価されます。
すべてのフィルタが AND 論理式に結合される前に行われます。
例:
国コードが「US OR UK」かつ商品コードが AFC の場合:
filters=COUNTRY_CODE%3D%3DUS,COUNTRY_CODE%3D%3DUK&filters=PRODUCT_CODE%3D%3DAFC
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[[["\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)"]]