Skip to content

Commit 6f49b9f

Browse files
committed
Show how segment can be used in Stats API
1 parent 002bb64 commit 6f49b9f

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

docs/stats-api.md

+8
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ List of values to match against. A data point matches filter if _any_ of the cla
237237

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

240+
#### Segments
241+
242+
[Segments](/filters-segments/#how-to-save-a-segment) can be used in filters, in the form `["is", "segment", [<segment_id>]]`. [See example](#example-filtering-by-segment)
243+
240244
#### Logical operations
241245

242246
Filters can be combined using `and`, `or` and `not` operators.
@@ -390,6 +394,10 @@ The following examples are interactive and can be edited and run against your ow
390394

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

397+
### Filtering by segment {#example-filtering-by-segment}
398+
399+
<ApiV2Example id="example-filtering-by-segment" />
400+
393401
### Timeseries query {#example-timeseries}
394402

395403
<ApiV2Example id="example-timeseries" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"site_id": "dummy.site",
3+
"metrics": ["visitors", "events"],
4+
"filters": [["is", "segment", [2]]],
5+
"date_range": "7d"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"results": [{"metrics": [0, 0], "dimensions": []}],
3+
"meta": {},
4+
"query": {
5+
"site_id": "dummy.site",
6+
"metrics": ["visitors", "events"],
7+
"date_range": ["2025-02-27T00:00:00+00:00", "2025-03-05T23:59:59+00:00"],
8+
"filters": [
9+
["has_not_done", ["is", "event:goal", ["Signup"]]],
10+
["is", "visit:source", ["opensource.com"]]
11+
],
12+
"dimensions": [],
13+
"order_by": [["visitors", "desc"]],
14+
"include": {},
15+
"pagination": {"offset": 0, "limit": 10000}
16+
}
17+
}

src/js/examples.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ 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-filtering-by-segment",
94+
title: "Filtering by segment",
95+
query: read("apiv2-examples/filtering-by-segment-query.json"),
96+
exampleResponse: read("apiv2-examples/filtering-by-segment-response.json"),
9197
}
98+
9299
]
93100

94101
export function getExampleCode(field: "query" | "exampleResponse", id: string, selectedSite: string | null): string {

0 commit comments

Comments
 (0)