Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/stats-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Filters allow limiting the data analyzed in a query. [See example](#example-filt

#### Simple filters

Each simple filter takes the form of `[operator, dimension, clauses]`.
Each simple filter is an array with three or four elements `[operator, dimension, clauses]` or `[operator, dimension, clauses, modifiers]`.

##### operators

Expand All @@ -187,6 +187,7 @@ The following operators are currently supported:
| `matches` | `["matches", "event:page", ["^/user/\d+$"]]` | Events where page matches regular expression `^/user/\d+$`. [Uses re2 syntax](https://github.com/google/re2/wiki/Syntax) |
| `matches_not` | `["matches", "event:page", ["^/user/\d+$"]]` | Events where page does not match regular expression `^/user/\d+$`. [Uses re2 syntax](https://github.com/google/re2/wiki/Syntax) |


##### dimension

[Event and visit dimensions](#dimensions) are valid for filters.
Expand All @@ -197,6 +198,12 @@ Note that only `is` operator is valid for `event:goal` dimension.

List of values to match against. A data point matches filter if _any_ of the clauses matches.

##### modifiers <Optional />

`contains` and `is` filters also support a 4th, modifier argument. For example, to match countries ignoring casing, you can use the following filter:

`["contains", "event:country", ["united", "EST], { "case_sensitive": false }]`. [See full example](#example-filtering-case-insensitive)

#### Logical operations

Filters can be combined using `and`, `or` and `not` operators.
Expand Down Expand Up @@ -341,6 +348,10 @@ The query that was executed, after manipulations performed on the backend.

<ApiV2Example id="example-filtering" />

### Case insensitive filtering {#example-filtering-case-insensitive}

<ApiV2Example id="example-filtering-case-insensitive" />

### Timeseries query {#example-timeseries}

<ApiV2Example id="example-timeseries" />
Expand Down
8 changes: 8 additions & 0 deletions src/js/apiv2-examples/filtering-case-insensitive-query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"site_id": "dummy.site",
"metrics": ["visitors"],
"date_range": "7d",
"filters": [
["contains", "event:page", ["blog"], {"case_sensitive": false}]
]
}
15 changes: 15 additions & 0 deletions src/js/apiv2-examples/filtering-case-insensitive-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"results": [{"metrics": [10], "dimensions": []}],
"meta": {},
"query": {
"site_id": "dummy.site",
"metrics": ["visitors"],
"date_range": ["2024-09-04T00:00:00+00:00", "2024-09-10T23:59:59+00:00"],
"filters": [
["contains", "event:page", ["/blog"], {"case_sensitive": false}]
],
"dimensions": [],
"order_by": [["visitors", "desc"]],
"include": {}
}
}
6 changes: 6 additions & 0 deletions src/js/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const EXAMPLES = [
query: read("apiv2-examples/filtering-basics-query.json"),
exampleResponse: read("apiv2-examples/filtering-basics-response.json"),
},
{
id: "example-filtering-case-insensitive",
title: "Case insensitive filtering",
query: read("apiv2-examples/filtering-case-insensitive-query.json"),
exampleResponse: read("apiv2-examples/filtering-case-insensitive-response.json"),
},
{
id: "example-timeseries",
title: "Timeseries query",
Expand Down
Loading