Elements

Last updated:

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

In PostHog, there is an API endpoint available to fetch the DOM elements captured by the autocapture functionality. The most interesting usecase for this is to be able to get all elements we have for a specific page, and how often that element has been interacted with.

Pagination

This endpoint has pagination. See Pagination for more info.

Element stats

/stats gives you an aggregate count of the number of events for each element. Internally we use this in the toolbar to show you a heatmap.

GET /element/stats/
GET /element/stats/?properties=[{"key":"$browser","value":"Chrome"}]
GET /element/stats/?properties=[{"key":"$browser","value":"Chrome"}]&date_from=-2d
AttributeTypeRequiredDescription
propertiesArray of PropertiesnoThe 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
date_fromDate or Relative DatenoDate from which to filter events from. Can be an iso date: 2020-06-18, or a relative date.
Some examples of relative dates:
- -2mStart the start of the month, 2 months ago
- -1y one year ago
- -1wEnd the end of the last week.
date_toDate or Relative DatenoDate from which to filter events to. Can be an iso date: 2020-06-18, or a relative date.
Some examples of relative dates:
- -2mStart the start of the month, 2 months ago
- -1y one year ago
- -1wEnd the end of the last week.

Example request:

curl https://posthog.example.com/api/elements/stats/

Example response:

[
{
"count": 245,
"hash": "31cd783c8572a24e1bd1912d8c436b72",
"elements": [
{
"text": null,
"tag_name": "div",
"attr_class": [
"container"
],
"href": null,
"attr_id": null,
"nth_child": 1,
"nth_of_type": 1,
"attributes": {
"attr__class": "container"
},
"order": 1
},
{
"text": "Sign up",
"tag_name": "a",
"attr_class": [
"btn",
"btn-lg",
"btn-success"
],
"href": "/demo/1",
"attr_id": "sign-up",
"nth_child": 5,
"nth_of_type": 1,
"attributes": {
"attr__id": "sign-up",
"attr__href": "/demo/1",
"attr__class": "btn btn-lg btn-success"
},
"order": 0
}
]
}
]

Elements

Lists all elements.

GET /element/
AttributeTypeRequiredDescription
propertiesArray of PropertiesnoThe 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

Example request:

curl https://posthog.example.com/api/elements/

Example response:

{
"count": 1009034,
"next": "https://app.posthog.com/api/element/?limit=100&offset=100",
"previous": null,
"results": [
{
"text": null,
"tag_name": "body",
"attr_class": null,
"href": null,
"attr_id": null,
"nth_child": 2,
"nth_of_type": 1,
"attributes": {},
"order": 10
},
{
"text": null,
"tag_name": "div",
"attr_class": null,
"href": null,
"attr_id": "root",
"nth_child": 1,
"nth_of_type": 1,
"attributes": {
"attr__id": "root"
},
"order": 9
},
]
}