Data model

Last updated:

Event (posthog_event)

PropertyTypeDescription
team_idForeignKey(Team)Link to the team
eventCharFieldName of the event.
There are default events that have special meaning within PostHog:
- $pageview captures a pageview
- $autocapture anything that was captured automatically by posthog-js. Includes clicks, changes to input and submissions of forms. Probably requires Elements to be created.
- $identify, which is used in the backend to set Person properties
- $create_alias, which creates an alias between a previous distinct_id and the current one
distinct_idCharFieldThe unique or anonymous id of the user that triggered the event.
NOTE: migration 0024 adds indexes to this, which is necessary for /paths to work reasonably quickly
propertiesJSONFieldAny key: value pairs in a dict.
- $current_url - we use this in a couple of places (like /paths, /events) as the url the user was visiting at that time.
timestampDateTimeFieldDefaults to timezone.now if not set
ipGenericIPAddressFieldIP of the user
elementsJSONFieldDeprecated in favour of the Element model

Element

At the moment, we're storing every element for every event, which means there's quite a lot of duplication. This is something that needs to be optimised.

PropertyTypeDescription
event_idForeignKey(Event)Link to the event
orderIntegerFieldThe order within all of the elements attached to that event. Starting from 0, which is the element that was clicked/interacted with
textCharFieldAll the text nodes of the element concatenated (note: that means text in the elements' children aren't included)
tag_nameCharFieldTag name of the element, lowercase. (a, button etc)
hrefCharFieldHref attribute of the link
(eg. <a href='https://posthog.com'>, stored as https://posthog.com)
attr_idCharFieldID attribute of the element
(eg. <button id="submit-form">, stored as submit-form)
attr_classArrayField(CharField)List of strings of classes on the element
(eg. <button className='btn btn-sm'>, stored as ['btn', 'btn-sm'])
nth_childIntegerFieldPosition of the element
(eg. <div><a>First</a><a>Second</a></div>, the second a would have nth_child=2)
nth_of_typeIntegerFieldPosition of the element of its own type
(eg. <div><strong>First</strong><a>Second</a></div>, the second a would have nth_of_type=1)
attributesCharFieldAny other attribute that wasn't set in the above properties (including data properties)