360 Secure SkillHub
360 安全技能中心

PostHog Query

该 Skill 指导使用 PostHog CLI 登录后执行 HogQL(ClickHouse 兼容 SQL)查询,可统计页面浏览量、事件数、趋势和近期事件,结果以 JSON 行输出;需具备 query:read 权限,并注意事件属性使用方括号语法。

quinlanjager
quinlanjager
热度 26.41
最近更新 2026-05-11 17:26:25
分类:数据依赖:代码执行 / 第三方 API / 读写文件应用场景:数据处理 / 研究

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add posthog-query
Metadata
name
posthog-query
description
Run SQL queries against PostHog product analytics data using the PostHog CLI. Use when checking pageviews, event counts, trends, or any analytics data from PostHog.
metadata
{"openclaw":{"emoji":"🦔","requires":{"bins":["posthog-cli"]},"install":"npm install -g posthog-cli"}}

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 editor
  • posthog-cli exp query check "<SQL>" — syntax/type check without running
  • Append --debug to run to 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 --debug flag returns full metadata including column types and cache status