Skip to content

Commit cbdb986

Browse files
authored
Merge pull request #586 from plausible/metmarkosaric-patch-28
Document Segments feature: How to create and how to use in API
2 parents e2ce28e + 6f49b9f commit cbdb986

5 files changed

+63
-3
lines changed

docs/filters-segments.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
---
2-
title: Using filters to segment your audience
2+
title: Filter and segment your audience
33
---
44

55
import useBaseUrl from '@docusaurus/useBaseUrl';
66

7-
Plausible Analytics allows you to easily segment your audience to analyze and understand the different trends. A segment is made up of one or more filters.
7+
Plausible Analytics allows you to easily segment your audience to analyze and understand the different trends. A segment is made up of one or more filters. You can save any segment for quick and convenient access.
8+
9+
## How to filter your dashboard
810

911
Any metric you click on in your dashboard creates a new filter. Click on any referral source, any of your pages or any location, device or goal and your dashboard will then show only the traffic for the metric you have selected.
1012

1113
You can mix and match filters too. So you can click on a referral source, then click on a country and then a goal to see all the traffic sent by the chosen referral source that is based in the selected country and that has converted on the selected goal.
1214

1315
Your current filters will be displayed on the top of your dashboard. You can click on the name of the existing filter to edit it or on the `x` icon to remove it.
1416

15-
You can remove all your filters by hitting the `Esc` key on your keyboard or by selecting `Clear all filters` in the filters menu that shows up when you're using multiple filters.
17+
You can remove all your filters by hitting the `Esc` key on your keyboard or by selecting `Clear all filters` in the filters menu (`***`).
1618

1719
<img alt="Mix and match filters to segment your audience" src={useBaseUrl('img/filter-by-source-and-country.png')} />
1820

@@ -64,4 +66,24 @@ Learn more on how Plausible [handles cross-subdomain tracking here](subdomain-ho
6466

6567
<img alt="List of subdomains" src={useBaseUrl('img/list-of-hostnames-and-subdomains.png')} />
6668

69+
## How to save a segment
70+
71+
Click on any metric in the dashboard or use the "**Filter**" button to filter your audience to a desired segment. After completing your segment, click on the "**Save as segment**" button that is visible in the filters menu (`***`) that you see when your dashboard is filtered.
72+
73+
Segments can be saved either as "**personal segments**" (these are visible only to you) or as "**site segments**" (these are visible to all the team members that have access to your dashboard).
74+
75+
Choose the type of segment you want to create, give it a recognizable name and click on the "**Save**" button.
76+
77+
### How to open a previously saved segment
78+
79+
Click the "**Filter**" button in the top-right corner of your dashboard to view your saved segments under the "**Segments**" heading. You can also search for specific segments. Click on a segment to open it in your dashboard.
80+
81+
Note that the "**Segments**" heading will only be visible in the "**Filter**" button after you save your first segment.
82+
83+
### How to edit or delete a previously saved segment
84+
85+
Open a previously saved segment and click its name in the top line of your Plausible dashboard. Then, select "**Edit segment**" to add or remove filters.
86+
87+
To save your changes, click the "**Update segment**" button. Use the arrow next to this button to save the existing segment as a brand new segment ("**Save as a new segment**) or to delete the existing segment ("**Delete segment**").
88+
6789
P.S. We've written an in-depth guide on effective use of audience segmentation, you can [read it here](https://plausible.io/audience-segmentation).

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)