Segment
Segments are named, logical expressions
of users. These segments may logically be built
using other segments as well. The segment api
provides a list of segments built by both the admin, pre-defined
segments automatically added to each account as well as custom ones
created through the UI.
Segments represent a number of concepts:
* *Segment* A list of users, users are members (or not) of a segment
* *Trigger* As a user enters, or leaves a segment, this is a trigger.
Triggers do not have a Size, only a history of events.
* *Goal* A segment that also implies conversion. In Lytics
App, there are *Goals* that show more prominently in a funnel
type interface.
* *Dynamic Attribute* A user belonging to a segment describes an attribute
about that user. For instance *IsPurchaser* is both an attribute
that can help personaliation, as well as a segment. We call these
special segments *Aspects* at Lytics.
* *Metric* A segment when used exclusively for the purposes of
tracking conversions/metric.
The Segment resource has the following attributes:
| field | DataType | Description |
|-------------|------------------|---------------|
| id | string | unique id, Lytics assigned
| created | Date | Created date
| updated | Date | Last Updated Date
| kind | string | What Type of segment from list above ["aspect","goal"] or leave empty for "segment".
| slug | string | customer-assigned unique id (We auto assigned by slugifying Name if not provided).
| name | string | Name of this segment
| description | string | Long text description (optional)
| is_public | bool | Is this segment available as part of user profile api (entity api)
| segment_ql | string | Segment QL Logical Expression
| tags | []string | List of tags, for organization purposes
To see a list of available fields available for segmentation rules see **catalog** api.
SegmentList
https://api.lytics.io/api/segmentGet list of **Segments** . Segments can refer to any Table.
The two main tables you will be working with are *User* and *Content*.
``
# Grab all segments from "user" table
curl "$LIOAPI/api/segment" -s -H "Authorization: $LIOKEY" | jq '.'
# Grab all "Content Collections" (ney, segments)
curl "$LIOAPI/api/segment?table=content" -s -H "Authorization: $LIOKEY" | jq '.'
``
Segment Create
https://api.lytics.io/api/segmentSegment Fetch
https://api.lytics.io/api/segment/{id}Fetch a segment by **id** or **slug**
URL Parameters
idrequiredstringExample:
my_segment_slugQuery Parameters
account_idoptionalstringHeaders
Authorizationoptionalstring{
"data": {
"id": "7a7f76ff97ad0e3e96c162f74aee8f8f",
"account_id": "4f7b525bdba058fc096757a6",
"author_id": "4f7b525bdba058fc096757a6",
"kind": "segment",
"segment_ql": "FILTER AND ( visits > 5, last_visit >= \"2015-04-01 00:00:00Z\", last_visit < \"2015-04-02 00:00:00Z\")",
"created": "2014-08-04T21:18:20.124Z",
"updated": "2014-08-04T21:18:20.124Z",
"description": "Casual users have been active in the last 90 days and show no extreme behavioral patterns.",
"name": "Recent Visits",
"slug_name": "recent_visits",
"tags": [
"email_trigger"
]
}
}Segment Update
https://api.lytics.io/api/segment/{id}Update A segment.
``
# You can upsert (insert if new, update if exists)
# by POSTing to api and the ALIAS will be used to lookup
# the existing one and update it.
curl -s -XPOST "https://api.lytics.io/api/segment" \
-H "Content-type: text/plain" \
-H "Authorization: $LIOKEY" \
-d'
FILTER AND (
visits > 5,
last_visit >= "now-30d",
scores.momentum > 10
)
ALIAS our_test_activelist
' | jq '.'
# Json Api Allows a few more fields such as description
curl -s -XPUT "https://api.lytics.io/api/segment/123456id" \
-H "Authorization: $LIOKEY" \
-H "Content-type: application/json" \
-d'
{
"name":"Most Active Users",
"segment_ql": "FILTER AND (visits > 5,last_visit >= \"now-30d\", scores.momentum > 10)",
"slug_name":"our_test_activelist",
"is_public": true,
"description":"a description of what this is for"
}
' | jq '.'
``
Segment Delete
https://api.lytics.io/api/segment/{id}Delete A segment.
URL Parameters
idrequiredstringExample:
my_segment_slugQuery Parameters
account_idoptionalstringHeaders
AuthorizationoptionalstringNo Content
SegmentSize
https://api.lytics.io/api/segment/sizeGet size of a single Segment using SegmentQL, not saved.
This api is very rate throttled, 1/10 seconds.
``
# Post a SegmentQL query to size api to fetch size
curl -s -XPOST "https://api.lytics.io/api/segment/size" \
-H "Content-type: text/plain" \
-H "Authorization: your_api_token" \
-d'
FILTER AND (
visits > 5,
last_visit >= "now-30d",
scores.momentum > 10
)
' | jq '.'
``
Headers
Authorizationoptionalstring{
"data": {
"id": "",
"name": "active",
"slug_name": "active",
"size": 10402
}
}SegmentValidate
https://api.lytics.io/api/segment/validateValidate single Segment Query Statement
Headers
Authorizationoptionalstring{
"status": 200,
"message": "success",
"data": null
}SegmentSizes
https://api.lytics.io/api/segment/sizesGet bunch of segment sizes.
Query Parameters
account_idoptionalstringidsrequiredstringExample:
123,456Headers
Authorizationoptionalstring{
"data": [
{
"id": "456dert",
"name": "Active",
"slug_name": "active",
"size": 10402
},
{
"id": "1234abcd",
"type": "custom",
"slug_name": "active",
"size": 45236
}
]
}SegmentScan
https://api.lytics.io/api/segment/{segId}/scanGet a paged list of **Users** for a **Segment**.
URL Parameters
segIdrequiredstringExample:
1234Query Parameters
account_idoptionalstringidoptionalstringExample:
1234limitoptionalstringExample:
10splitsoptionalstringExample:
1,2,3startoptionalstringExample:
next_xyzmetaoptionalstringExample:
truesortfieldoptionalstringExample:
last_visit_tssortorderoptionalstringExample:
20recentoptionalstringExample:
truesegmentsoptionalstringExample:
{rules...}fieldsoptionalstringExample:
email,user_id,nameHeaders
Authorizationoptionalstringnull
Segment Batch Delete
https://api.lytics.io/api/segment/{segId}/scanSegmentAttribution
https://api.lytics.io/api/segment/{segId}/attributionGet single attribution
URL Parameters
segIdrequiredstringExample:
123abcQuery Parameters
account_idoptionalstringlimitoptionalstringrefreshoptionalstringHeaders
Authorizationoptionalstring{
"data": [
{
"id": "1234",
"metrics": [
{
"ts": "1413149713466",
"value": 1002
},
{
"ts": "1413149713455",
"value": 1005
}
]
},
{
"id": "1111",
"metrics": [
{
"ts": "1413149713466",
"value": 1002
},
{
"ts": "1413149713455",
"value": 1005
}
]
}
]
}SegmentAttributionList
https://api.lytics.io/api/segment/attributionGet bunch of segment sizes
Query Parameters
account_idoptionalstringrefreshoptionalstringlimitoptionalstringidsrequiredstringExample:
123,456Headers
Authorizationoptionalstring{
"data": [
{
"id": "1234",
"metrics": [
{
"ts": "1413149713466",
"value": 1002
},
{
"ts": "1413149713455",
"value": 1005
}
]
},
{
"id": "1111",
"metrics": [
{
"ts": "1413149713466",
"value": 1002
},
{
"ts": "1413149713455",
"value": 1005
}
]
}
]
}SegmentFieldInfo
https://api.lytics.io/api/segment/{segId}/fieldinfoGet field info by segment
URL Parameters
segIdrequiredstringExample:
123,abc,defQuery Parameters
account_idoptionalstringlimitoptionalstringfieldsoptionalstringExample:
name,email,segmentsHeaders
Authorizationoptionalstringnull