AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

querying-posthog-data

Explains how to query PostHog data, defaulting to typed runners for supported product analytics. Read it before you write HogQL/SQL. Also read it before you call execute-sql against PostHog. Use it to find or aggregate PostHog entities. These entities include insights, dashboards, cohorts, feature flags, experiments, surveys, hog flows, warehouse data, and persons. Use it for trends, funnels, retention, lifecycle, paths, stickiness, web analytics, error tracking, logs, sessions, and LLM traces. Before you calculate a governed business or telemetry measure, check system.information_schema.metrics for an approved definition. Examples include MRR, activation, billable usage, active organizations, and failure rates. Use the approved definition before you derive a measure from raw events or use a typed domain tool. It also covers HogQL differences, system table schemas, functions, query examples, and schema discovery.

Original source
posthog
License
MIT
Pinned revision
cac7c80a9e5b73484d18eda1bffb47297c938e0c

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read posthog--querying-posthog-data at revision cac7c80a9e5b73484d18eda1bffb47297c938e0c, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 65

references/example-error-tracking.md

Error tracking (search for a value in an error and filtering by custom properties)

SELECT
    fp_state.issue_id AS id,
    any(fp_state.issue_status) AS status,
    any(fp_state.issue_severity) AS severity,
    any(fp_state.issue_name) AS name,
    any(fp_state.issue_description) AS description,
    any(fp_state.assigned_user_id) AS assignee_user_id,
    any(fp_state.assigned_role_id) AS assignee_role_id,
    min(fp_state.first_seen) AS first_seen,
    max(ev.last_seen_fp) AS last_seen,
    argMaxMerge(ev.function_state) AS function,
    argMaxMerge(ev.source_state) AS source,
    sum(ev.occ) AS occurrences,
    least(uniqMerge(ev.sessions_state), sum(ev.occ)) AS sessions,
    least(uniqMerge(ev.users_state), sum(ev.occ)) AS users,
    sumForEach(arrayMap(i -> if(equals(ev.bin_idx, i), ev.occ, _toUInt64(0)), range(0, 20))) AS volumeRange,
    argMaxMerge(ev.library_state) AS library
FROM
    (SELECT
        cityHash64(JSONExtractString(e.properties, '$exception_fingerprint')) AS fp_hash,
        max(timestamp) AS last_seen_fp,
        argMaxState(properties.$exception_functions.-1, timestamp) AS function_state,
        argMaxState(properties.$exception_sources.-1, timestamp) AS source_state,
        argMaxState(properties.$lib, timestamp) AS library_state,
        least(19, intDiv(dateDiff('seconds', toDateTime(toDateTime('2026-10-29 12:00:00.000000')), timestamp), greatest(1, intDiv(dateDiff('seconds', toDateTime(toDateTime('2026-10-29 12:00:00.000000')), toDateTime(toDateTime('2026-10-30 12:02:53.638503'))), 20)))) AS bin_idx,
        count() AS occ,
        uniqState(nullIf(e.$session_id, '')) AS sessions_state,
        uniqState(coalesce(nullIf(toString(e.event_person_id), '00000000-0000-0000-0000-000000000000'), e.distinct_id)) AS users_state
    FROM
        events AS e
    WHERE
        and(equals(e.event, '$exception'), isNotNull(e.properties.$exception_fingerprint), true, greaterOrEquals(e.timestamp, toDateTime(toDateTime('2026-10-29 12:00:00.000000'))), lessOrEquals(e.timestamp, toDateTime(toDateTime('2026-10-30 12:02:53.638503'))), or(greater(multiSearchAnyCaseInsensitive(toString(e.properties.$exception_types), ['constant']), 0), greater(multiSearchAnyCaseInsensitive(toString(e.properties.$exception_values), ['constant']), 0), greater(multiSearchAnyCaseInsensitive(toString(e.properties.$exception_sources), ['constant']), 0), greater(multiSearchAnyCaseInsensitive(toString(e.properties.$exception_functions), ['constant']), 0), greater(multiSearchAnyCaseInsensitive(toString(e.properties.email), ['constant']), 0), greater(multiSearchAnyCaseInsensitive(toString(e.person.properties.email), ['constant']), 0)), equals(properties.tag, 'max_ai'))
    GROUP BY
        fp_hash,
        bin_idx) AS ev
    INNER JOIN error_tracking_fingerprint_issue_state AS fp_state ON equals(ev.fp_hash, fp_state.fp_hash)
WHERE
    isNotNull(fp_state.issue_id)
GROUP BY
    id
ORDER BY
    last_seen DESC,
    id DESC
LIMIT 50000