Segment
Overview
The segment
parameter allows you to define behavioral segments for your analysis. Segments can filter your data based on specific user behaviors and characteristics across different scopes.
Parameters
Main Parameters
Parameter | Description | Values | Required |
---|---|---|---|
scope | Defines the segmentation type | visit_id , user_id , visitor_id , event_id , av_session_id , cart_id , pageview_id | Yes |
segmentKey | Reference to a saved segment | String | No |
content | Segment definition (see below) | Object | Yes (if no segmentKey) |
mode | Include or exclude the behavior | include , exclude | Yes |
period | Time period for the behavior (visitor/user segments) | See Period documentation | No |
space | Sites where behavior occurred (visitor/user segments) | See Sites documentation | No |
Content Parameters
Parameter | Description | Values | Required |
---|---|---|---|
condition | Contains the filter for the segment | Object | Yes |
filter | Describes the behavior to track | See Filter documentation | Yes |
Scope Types
Find detailed information about different segmentation scopes in the help center.
Examples
Example 1: Simple device type segment
Segment visitors using desktop devices.
{
"segment": {
"section": {
"scope": "visit_id",
"content": {
"condition": {
"filter": {
"device_type": {
"$eq": "Desktop"
}
}
}
},
"mode": "include"
}
}
}
Example 2: Visitor segment with time period
Segment visitors from France in the previous month.
{
"segment": {
"section": {
"scope": "visitor_id",
"mode": "include",
"period": {
"p1": [
{
"type": "R",
"granularity": "M",
"startOffset": -1,
"endOffset": -1
}
]
},
"content": {
"condition": {
"filter": {
"visit_geo_country": {
"$eq": "France"
}
}
}
}
}
}
}
Example 3: Using saved segment
Reference a previously saved segment.
{
"segment": {
"section": {
"segmentKey": "mobile_users_france",
"mode": "include"
}
}
}