Posthog Query
Run SQL queries against PostHog product analytics data using the PostHog CLI.
- Rating
- 4.4 (418 reviews)
- Downloads
- 5,858 downloads
- Version
- 1.0.0
Overview
Run SQL queries against PostHog product analytics data using the PostHog CLI.
Complete Documentation
View Source →
PostHog Query Skill
Run HogQL (ClickHouse-compatible SQL) queries against PostHog via the CLI.
One-Time Setup
posthog-cli login # authenticate interactively; stores token in ~/.posthog/credentials.json
Requires API key scope: query:read.
Command
posthog-cli exp query run "<SQL>"
Results are printed as JSON lines to stdout. The CLI reads auth from ~/.posthog/credentials.json (set up via posthog-cli login).
Property Access Syntax
Use bracket notation for event properties — dot notation with quoted keys does not work:
-- ✅ Correct
properties['$current_url']
properties['$browser']
-- ❌ Wrong
properties.'$current_url'
Examples
Count all pageviews:
posthog-cli exp query run "SELECT count() as pageviews FROM events WHERE event = '\$pageview'"
Filter by URL:
posthog-cli exp query run "SELECT count() as pageviews FROM events WHERE event = '\$pageview' AND properties['\$current_url'] LIKE 'https://example.com/%'"
7-day daily trend:
posthog-cli exp query run "SELECT toDate(timestamp) as date, count() as pageviews FROM events WHERE event = '\$pageview' AND timestamp >= now() - INTERVAL 7 DAY GROUP BY date ORDER BY date"
Recent events:
posthog-cli exp query run "SELECT event, timestamp FROM events ORDER BY timestamp DESC LIMIT 10"
Other Subcommands
posthog-cli exp query editor— interactive query editorposthog-cli exp query check "— syntax/type check without running" - Append
--debugtorunto get the full JSON response (columns, types, cache info)
Notes
- HogQL is ClickHouse-compatible SQL — standard ClickHouse functions apply
- Shell-escape
$in event names:'\$pageview'or use double quotes carefully - The
--debugflag returns full metadata including column types and cache status
Installation
openclaw install posthog-query
💻Code Examples
posthog-cli login # authenticate interactively; stores token in ~/.posthog/credentials.json
Requires API key scope: `query:read`.
## Commandposthog-cli exp query run "<SQL>"
Results are printed as JSON lines to stdout. The CLI reads auth from `~/.posthog/credentials.json` (set up via `posthog-cli login`).
## Property Access Syntax
Use bracket notation for event properties — dot notation with quoted keys does not work:properties.'$current_url'
## Examples
**Count all pageviews:**-- ✅ Correct
properties['$current_url']
properties['$browser']
-- ❌ Wrong
properties.'$current_url'Tags
Quick Info
Ready to Install?
Get started with this skill in seconds
Related Skills
4claw
4claw — a moderated imageboard for AI agents.
Aap Passport
Agent Attestation Protocol - The Reverse Turing Test.
Adaptive Suite
A continuously adaptive skill suite that empowers Clawdbot.
Adversarial Prompting
Adversarial analysis to critique, fix.