Insights

Last updated:

For instructions on how to authenticate to use this endpoint, see API overview.

The /api/insight/ endpoints allow you to fetch insights that provides advanced analytics on the data from PostHog.

Endpoints

Insight

GET
/api/insight

Get a list of insights from PostHog.

Query parameters

ParameterType / Valid ValuesDescriptionRequired
propertiesArray of PropertiesThe key/values that you want to filter on. Basic usage is: [{"key": "$browser", "value": "Chrome"}]

For each property, you can specify:
- key Key of the property
- value Value you want to filter on
- type Either person or event
- operator, any of:
-- exact/empty
--is_not
--icontains
--not_icontains
--gt
--lt
--is_set
savedboolean
userstring
insight- "SESSIONS"
- "PATHS"
- "TRENDS"
- "FUNNELS"
- "RETENTION"

Example

Request
GET /api/insight/?insight=SESSIONS
Response
HTTP 200 OK
Content-Type: application/json
{
"count": 4,
"next": null,
"previous": null,
"results": [
{
"id": 176124,
"name": null,
"filters": {
"events": [
{
"id": "$pageview",
"math": null,
"name": "$pageview",
"type": "events",
"order": 0,
"properties": [],
"math_property": null
}
],
"display": "ActionsLineGraph",
"filters": [],
"insight": "SESSIONS",
"session": "avg",
"interval": "day",
"pagination": {}
},
"filters_hash": "cache_24b6b973559c99cfffb8a02e3d412ae2",
"order": null,
"deleted": false,
"dashboard": null,
"layouts": {},
"color": null,
"last_refresh": "2021-05-02T05:10:24.682389Z",
"refreshing": false,
"result": null,
"created_at": "2021-04-28T11:29:02.413232Z",
"saved": false,
"created_by": {
"id": 2961,
"uuid": "01791342-cc0d-0000-57e5-d8dc4b42cc57",
"distinct_id": "AdCojLadUwWOfT0V6qO15URj1spDVKx-c4itZm28QSk",
"first_name": "",
"email": "test@example.com"
}
},
]
}

Trend

GET
/api/insight/trend

Get a list of trends from PostHog.

Query parameters

ParameterType / Valid ValuesDescriptionRequired
eventsArray of EventsBasic usage is [{"id": "$pageview"}].

For each event, you can specify:
- id Name of the event
- properties A Properties object (see below)
- order (int) order of the event. This is mostly used for funnels
propertiesArray of PropertiesThe key/values that you want to filter on. Basic usage is: [{"key": "$browser", "value": "Chrome"}]

For each property, you can specify:
- key Key of the property
- value Value you want to filter on
- type Either person or event
- operator, any of:
-- exact/empty
--is_not
--icontains
--not_icontains
--gt
--lt
--is_set
intervalstringInterval of the data. minute, hour, day, week, month
breakdown_valuestringSplit out all entities by any property value or cohort id.
breakdown_typestringDefault: property. Can be set to cohort, in which case you can pass through a cohort_id to breakdown_value
from_dashboardstring
shown_as- "volume"
- "stickiness"

Example

Request
GET /api/insight/trend/?events=[{"id":"$pageview"}]&interval=week
Response
HTTP 200 OK
Content-Type: application/json
{
"result": [
{
"action": {
"id": "$pageview",
"type": "events",
"order": null,
"name": "$pageview",
"math": null,
"math_property": null,
"properties": []
},
"label": "$pageview",
"count": 84.0,
"data": [
0.0,
69.0,
15.0
],
"labels": [
"Sun. 18 April",
"Sun. 25 April",
"Sun. 2 May"
],
"days": [
"2021-04-18",
"2021-04-25",
"2021-05-02"
]
}
],
"next": null
}

Session

GET
/api/insight/session

Get a list of sessions from PostHog.

Query parameters

ParameterType / Valid ValuesDescriptionRequired
propertiesArray of PropertiesThe key/values that you want to filter on. Basic usage is: [{"key": "$browser", "value": "Chrome"}]

For each property, you can specify:
- key Key of the property
- value Value you want to filter on
- type Either person or event
- operator, any of:
-- exact/empty
--is_not
--icontains
--not_icontains
--gt
--lt
--is_set
sessionstringSpecifies the type of operation to perform on session duration values. For example, avg, or dist.

Example

Request
GET /api/insight/session?session=avg
Response
HTTP 200 OK
Content-Type: application/json
{
"result": [
{
"data": [
0.0,
0.0,
0.0,
10.12,
8.5,
33.9,
9.65,
0.1
],
"labels": [
"Mon. 26 April",
"Tue. 27 April",
"Wed. 28 April",
"Thu. 29 April",
"Fri. 30 April",
"Sat. 1 May",
"Sun. 2 May",
"Mon. 3 May"
],
"days": [
"2021-04-26",
"2021-04-27",
"2021-04-28",
"2021-04-29",
"2021-04-30",
"2021-05-01",
"2021-05-02",
"2021-05-03"
],
"label": "Average Session Length (minutes)",
"count": 12,
"chartLabel": "Average Session Length (minutes)"
}
],
"last_refresh": "2021-05-03T05:10:18.712759Z",
"is_cached": true
}

Path

GET
/api/insight/path

Get a list of paths from PostHog.

Query parameters

ParameterType / Valid ValuesDescriptionRequired
propertiesArray of PropertiesThe key/values that you want to filter on. Basic usage is: [{"key": "$browser", "value": "Chrome"}]

For each property, you can specify:
- key Key of the property
- value Value you want to filter on
- type Either person or event
- operator, any of:
-- exact/empty
--is_not
--icontains
--not_icontains
--gt
--lt
--is_set
request_typestring
startstring

Example

Request
GET /api/insight/path/?properties=[{"key":"$browser","value":"Chrome"}]&start=http://localhost:1313/
Response
HTTP 200 OK
Content-Type: application/json
{
"result": [
{
"source": "1_http://localhost:1313/",
"source_id": "017926d6-3fb8-0000-ac2d-a1261e215135",
"target": "2_http://localhost:1313/portfolio/",
"target_id": "017926d6-bd2f-0000-2fc5-23537f3a66a8",
"value": 1
},
{
"source": "1_http://localhost:1313/blog/",
"source_id": "0179221e-5d3c-0000-561f-850d00218ea1",
"target": "2_http://localhost:1313/about/",
"target_id": "0179221e-7142-0000-287a-8a8c4058d671",
"value": 1
},
{
"source": "2_http://localhost:1313/about/",
"source_id": "0179221e-7142-0000-287a-8a8c4058d671",
"target": "3_http://localhost:1313/blog/",
"target_id": "0179221e-75e4-0000-256e-48bcc5660654",
"value": 1
},
{
"source": "2_http://localhost:1313/portfolio/",
"source_id": "017926d6-bd2f-0000-2fc5-23537f3a66a8",
"target": "3_http://localhost:1313/portfolio/",
"target_id": "017926de-04ea-0000-42cf-c964644e646a",
"value": 1
},
{
"source": "3_http://localhost:1313/blog/",
"source_id": "0179221e-75e4-0000-256e-48bcc5660654",
"target": "4_http://localhost:1313/portfolio/",
"target_id": "0179221e-865e-0000-3851-10a4a7f5ec7c",
"value": 1
},
{
"source": "3_http://localhost:1313/portfolio/",
"source_id": "017926de-04ea-0000-42cf-c964644e646a",
"target": "4_http://localhost:1313/portfolio/posthog/",
"target_id": "017926de-2d06-0000-ba31-070c446839a5",
"value": 1
}
]
}