tools-and-features-hogql

โดย posthog

HogQL queries for PostHog analytics

npx skills add https://github.com/posthog/skills --skill tools-and-features-hogql

HogQL queries for PostHog

This skill helps you write HogQL queries for PostHog analytics. HogQL is PostHog's SQL dialect, a wrapper around ClickHouse SQL with simplified property access and PostHog-specific functions.

Reference files

  • references/expressions.md - Sql expressions - docs
  • references/aggregations.md - Supported aggregations - docs
  • references/clickhouse-functions.md - Supported clickhouse functions - docs
  • references/data-access.md - Accessing data using sql - docs
  • references/variables.md - Sql variables - docs
  • references/useful-functions.md - Useful sql functions - docs
  • references/posthog.md - PostHog table schemas (events, persons, groups, sessions)
  • references/sessions.md - Sessions - docs

Consult the documentation for SQL syntax, available functions, and query patterns.

Key principles

  • Property access: Use properties.$property_name for event properties and person.properties.$property_name for person properties
  • Null handling: HogQL has simplified null handling compared to raw ClickHouse SQL
  • Filters placeholder: Use {filters} in queries to allow UI-based filtering in PostHog dashboards
  • Aggregations: Prefer ClickHouse aggregation functions like count(), uniq(), avg(), sum()

Common patterns

Event queries

SELECT event, count()
FROM events
WHERE {filters}
GROUP BY event
ORDER BY count() DESC

Property breakdowns

SELECT properties.$browser AS browser, count()
FROM events
WHERE event = '$pageview' AND {filters}
GROUP BY browser

Person properties

SELECT person.properties.email, count()
FROM events
WHERE {filters}
GROUP BY person.properties.email

Framework guidelines

  • Use properties.$name syntax for event properties, person.properties.$name for person properties
  • Use bracket notation for special characters like properties['$feature/cool-flag']
  • For cohorts, filter with person_id IN COHORT 'cohort-name'
  • For actions, use matchesAction('action-name') in WHERE clauses
  • Include {filters} placeholder in WHERE clauses to enable UI-based filtering in dashboards
  • Use {variables.name} for reusable SQL variables across dashboards
  • Access dashboard date range with {filters.dateRange.from} and {filters.dateRange.to}
  • ALWAYS include a time range filter - shorter is faster (e.g., timestamp >= now() - INTERVAL 7 DAY)
  • Prefer uniq() over count(distinct) for counting unique values - it's more efficient
  • Don't scan the same table multiple times - use materialized views for reusable subsets
  • Use timestamp-based pagination instead of OFFSET for large datasets
  • Name queries descriptively for easier debugging in query_log
  • Use dateTrunc() for time-based grouping (e.g., dateTrunc('day', timestamp))
  • For funnel queries, use windowFunnel() or sequenceMatch() functions
  • Test queries in the PostHog SQL editor before using them in insights or the API

Skills เพิ่มเติมจาก posthog

managing-experiment-lifecycle
posthog
แนะนำการเปลี่ยนสถานะการทดลอง: การเริ่ม, หยุดชั่วคราว, ดำเนินต่อ, สิ้นสุด, จัดส่งรูปแบบ, เก็บถาวร, รีเซ็ต, และทำซ้ำ ครอบคลุมเงื่อนไขเบื้องต้น...
official
configuring-experiment-analytics
posthog
Configures the analytics side of a PostHog experiment — exposure criteria (default `$feature_flag_called` vs custom exposure events), primary and secondary…
official
error-tracking-hono
posthog
การติดตามข้อผิดพลาดของ PostHog สำหรับ Hono
official
error-tracking-react
posthog
PostHog การติดตามข้อผิดพลาดสำหรับ React
official
integration-android
posthog
PostHog integration สำหรับแอปพลิเคชัน Android
official
integration-ruby
posthog
PostHog การผสานรวมสำหรับแอปพลิเคชัน Ruby ใดๆ ที่ใช้ Ruby SDK
official
tuning-incremental-sync-config
posthog
การกำหนดค่าการซิงค์จะอยู่บน ExternalDataSchema และสามารถเปลี่ยนแปลงได้ตลอดเวลาผ่าน external-data-schemas-partial-update การเปลี่ยนแปลงส่วนใหญ่จะไม่ทำลายข้อมูล (มีผลในการซิงค์ครั้งถัดไป) แต่บางอย่าง (การเปลี่ยน sync_type, การเปลี่ยนคีย์หลัก) จำเป็นต้องจัดการอย่างระมัดระวังเพื่อหลีกเลี่ยงการทำให้ข้อมูลที่ซิงค์เสียหาย
official
instrument-integration
posthog
ใช้สกิลนี้เพื่อเพิ่ม PostHog SDK ลงในแอปพลิเคชัน ใช้เมื่อตั้งค่า PostHog เป็นครั้งแรก หรือตรวจสอบ PR ที่ต้องการการเริ่มต้นใช้งาน PostHog ครอบคลุมการติดตั้ง SDK การตั้งค่า provider และการกำหนดค่าพื้นฐาน รองรับเฟรมเวิร์กหรือภาษาใดก็ได้
official