posthog source runs a HogQL query in PostHog and charts its result next to your other
sources. It works with PostHog Cloud (US and EU) and with a self-hosted PostHog instance. Write the
query to aggregate events, such as one row per day and plan, and define metrics on its columns like
on any table.
1. Create an API key
In PostHog, open Settings → Personal API keys and create a key with the Query Read scope, limited to the project the dashboards read. Note the project’s id from its project settings.hatchmark.yaml.
2. Add the source
hostdefaults to US Cloud,https://us.posthog.com. Sethttps://eu.posthog.comfor EU Cloud, or the URL of your own instance.max_agereuses the result for an hour, sodevand repeated builds don’t query PostHog again.
3. Define metrics on it
sum of the daily counts. A distinct count, such as the people active in a month,
cannot be added up from daily rows: someone active on two days would count twice. Count it in the
query at the grain the dashboard shows, such as one row per month, or return one row per person and
day and use count_distinct in Hatchmark, within the row limit below.
Keep the query small
PostHog’s query API is meant for aggregate queries. PostHog asks third-party tools not to use it to export events in bulk, and limits it: a query runs for at most 10 seconds, three run at once per project, and queries count against hourly request limits and a budget of bytes read. One result holds fewer than 50,000 rows. So:- aggregate in the query (
count(),sum(),uniqExact()withGROUP BY) instead of selecting events; - bound
timestampto the days the dashboards show and filter onevent; - set
max_ageso a build reuses the last result.
HM2051 rather than showing part of the data,
and a rate limit stops it with HM2059, which says how long to wait when PostHog sends a wait. Use uniqExact for
distinct counts: uniq is an estimate.
Time zones
Hatchmark reads every PostHog date-time as an instant and buckets it in the project’stimezone.
Hatchmark asks PostHog to run the query in UTC, so toDate(timestamp) and date literals without a
zone use UTC, not the PostHog project’s time zone. A saved PostHog SQL insight that buckets days in the
project’s zone gives other days here. Name the zone in the query, as above, or return toStartOfHour(timestamp) and let
Hatchmark bucket the hours into days.
See PostHog in the sources reference for every option and how each
column type is read.