Skip to content

Commit 7e11022

Browse files
committed
Document behavioral filters
1 parent cef8b48 commit 7e11022

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

docs/stats-api.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ List of values to match against. A data point matches filter if _any_ of the cla
236236

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

239-
#### Logical operations
239+
#### Logical filters
240240

241241
Filters can be combined using `and`, `or` and `not` operators.
242242

@@ -248,6 +248,20 @@ Filters can be combined using `and`, `or` and `not` operators.
248248

249249
Note that top level filters is wrapped in an implicit `and`.
250250

251+
#### Behavioral filters
252+
253+
Behavioral filters can be used to filter whether a user has ever done or not done something. This can be used to filter out users who have not completed a goal or
254+
who have visited a particular page.
255+
256+
| Operator | Example | Explanation |
257+
| -- | -- | -- |
258+
| `has_done` | `["has_done", ["is", "event:page", ["/pricing"]]]` | Users who have done a pageview to /pricing page |
259+
| `has_not_done` | `["has_not_done", ["is", "event:goal", ["Login"]]]` | Users who have not done Login goal |
260+
261+
Behavioral filters can only be used with [event dimension](#event-dimensions) filters.
262+
263+
[See example](#example-behavioral-filters)
264+
251265
### order_by <Optional />
252266

253267
Allows for custom ordering of query results.
@@ -389,6 +403,12 @@ The following examples are interactive and can be edited and run against your ow
389403

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

406+
### Behavioral filters {#example-behavioral-filters}
407+
408+
This example shows how many visitors and how many times visitors have visited the `/pricing` page, needed support before or after and not created an account or logged in.
409+
410+
<ApiV2Example id="example-behavioral-filters" />
411+
392412
### Timeseries query {#example-timeseries}
393413

394414
<ApiV2Example id="example-timeseries" />
@@ -415,7 +435,6 @@ In this example, imported data could not be included due to dimension and filter
415435

416436
<ApiV2Example id="example-imports-warning" />
417437

418-
419438
### Revenue metrics {#example-revenue-metrics}
420439

421440
<ApiV2Example id="example-revenue-metrics" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"site_id": "dummy.site",
3+
"metrics": ["visitors", "pageviews"],
4+
"date_range": "7d",
5+
"filters": [
6+
["is", "event:page", ["/pricing"]],
7+
["has_done", ["is", "event:goal", ["Open Support Chat"]]],
8+
["has_not_done", ["is", "event:goal", ["Register", "Login"]]]
9+
]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"results": [{"metrics": [1533, 3429], "dimensions": []}],
3+
"meta": {},
4+
"query": {
5+
"site_id": "dummy.site",
6+
"metrics": ["visitors", "pageviews"],
7+
"date_range": ["2025-01-10T00:00:00+00:00", "2025-01-16T23:59:59+00:00"],
8+
"filters": [
9+
["is", "event:page", ["/pricing"]],
10+
["has_done", ["is", "event:goal", ["Open Support Chat"]]],
11+
["has_not_done", ["is", "event:goal", ["Register", "Login"]]]
12+
],
13+
"dimensions": [],
14+
"order_by": [["visitors", "desc"]],
15+
"include": {},
16+
"pagination": {"offset": 0, "limit": 10000}
17+
}
18+
}

src/js/examples.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ const EXAMPLES = [
8888
title: "Revenue metrics could not be calculated",
8989
query: read("apiv2-examples/revenue-warning-query.json"),
9090
exampleResponse: read("apiv2-examples/revenue-warning-response.json"),
91+
},
92+
{
93+
id: "example-behavioral-filters",
94+
title: "Behavioral filters",
95+
query: read("apiv2-examples/behavioral-filters-query.json"),
96+
exampleResponse: read("apiv2-examples/behavioral-filters-response.json"),
9197
}
9298
]
9399

0 commit comments

Comments
 (0)