querying-canvas-data
Fungsinya
Skill ini menunjukkan cara canvas memuat data dari PostHog dengan aman dan akurat. Ditujukan untuk pembuat yang ingin angka di canvas mereka sama dengan insight dan laporan yang sudah mereka percaya.
Kapan dipakai
- βSaat canvas perlu menampilkan metrik dari PostHog.
- βSaat angka di canvas tidak sama dengan insight PostHog tempat angka itu berasal.
- βSaat Anda ingin metrik canvas tertaut kembali ke insight tersimpannya.
Link skill
https://github.com/PostHog/posthog/blob/master/products/canvas/skills/querying-canvas-data/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTampilkan pengguna aktif mingguan kami di canvas ini, dan pastikan angkanya sama dengan insight tersimpan kami.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
AI lebih memilih memuat insight tersimpan yang sudah ada, sehingga angkanya tetap identik dengan PostHog. Setelah itu, AI menggunakan kueri bertipe, dan SQL inline hanya sebagai pilihan terakhir, lalu menampilkan hasilnya.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Querying canvas data
The ph bridge is the only way a canvas talks to PostHog. Import it with
import { ph } from "@posthog/canvas-sdk" β a platform-provided module, so it needs no
dependencies entry. The same object is also installed as the window.ph global, which existing
canvases use; prefer the import in new code. Its typed surface is
references/canvas-sdk.d.ts. Never initialize it: credentials stay in
the host, and fetch(), posthog-js, and hand-rolled clients cannot reach PostHog from the sandbox.
External requests and resources require a non-PostHog origin declared in
capabilities.network.origins, and work only in the published canvas β the edit-mode preview
blocks all direct network access. This includes external stylesheets; remote scripts remain
blocked.
Data hierarchy β back every metric with a saved insight
- Preferred β save an insight, load it by reference. Use the PostHog MCP insight tools to
create/save an insight that computes the metric with an insight query type (TrendsQuery,
FunnelsQuery, RetentionQuery, PathsQuery, or the web-analytics kinds WebOverviewQuery /
WebStatsTableQuery β not raw SQL). Confirm its numbers, note the
short_id, and render it withawait ph.loadInsight(shortId, { dateRange }). These are proven queries β numbers match the PostHog UI exactly (sessionization, unique users, breakdowns, bounce rate). Never fabricate a query or guess event/property names; discover and save them via MCP first. - Secondary β an ad-hoc typed node:
ph.query({ kind: "TrendsQuery", series: [...], dateRange: {...} })when saving an insight genuinely doesn't fit. - Last resort β inline HogQL:
ph.query("SELECT β¦"), only when no insight kind can express the metric; you then own the SQL and its date window.
For web-analytics boards specifically, use the web-analytics query kinds β raw HogQL subtly gets bounce rate, sessionization, channel attribution, and unique-visitor counts wrong.
Whatever tier you use, declare it in the project's capabilities before publishing: every
ph.loadInsight short id in capabilities.posthog.insights, every ph.capture event name in
captureEvents, and inlineQueries: true for any ph.query use. The host rejects undeclared
calls at runtime, and validation fails on undeclared literals.
Verifiability β every claim must be checkable in PostHog
A number a viewer cannot verify is a number they cannot trust. Every data-backed figure a canvas shows β a KPI, a chart, a table, a stated conclusion β must carry the verification affordance for its tier:
- Insight-backed metrics link the real insight in PostHog. For a metric loaded from a saved
insight (the preferred tier), render a "View in PostHog" affordance that calls
ph.openExternal(insightUrl)from a click. Mint the URL at authoring time with thegenerate-app-urlMCP tool (path template/insights/{id}with the insight's short id) and bake the returned URL into the source verbatim β never hand-build one.ph.openExternalonly openshttps://*.posthog.comURLs and only from a user gesture, so wire it to a button or link, never to load or render. Do not also bake the insight's saved query text into the source: canvas source is readable by every canvas viewer, while access to the insight itself is enforced by PostHog β the link is where a viewer inspects the query, with their own permissions applied. - Ad-hoc queries disclose the exact query that ran, viewable in place. For a figure computed
by
ph.query(a typed node or inline HogQL), show the query behind it β the HogQL text, or the typed query node pretty-printed as JSON β in a modal or a collapsed disclosure attached to the card (a QuillDialogorCollapsiblein a React canvas, a<details>element in an HTML one). Render it from the same constant or builder you pass toph.query, so the displayed query can never drift from the executed one. This discloses nothing beyond what the viewer already runs:ph.queryexecutes as the signed-in viewer.
These are not optional polish: a canvas that presents PostHog data without them is incomplete. Keep the affordances compact β a small link icon per insight-backed card, a "View query" disclosure per ad-hoc card, or one shared modal listing every ad-hoc query the canvas runs, each labeled with the figure it backs.
For a status board, set refresh to the cache lifet
Pertanyaan umum
Mengapa harus menyimpan insight terlebih dahulu?
Insight tersimpan menggunakan logika kueri PostHog sendiri, sehingga angkanya sama persis dengan tampilan PostHog.
Bisakah canvas menjalankan kueri mentah?
Bisa, tetapi itu pilihan terakhir. Kueri inline menampilkan kueri persis yang dijalankan, sehingga membantu orang memverifikasi angkanya.
Apakah canvas memerlukan kunci API?
Tidak. Kredensial tetap berada di dalam PostHog, dan canvas menggunakan jembatan data sebagai gantinya.
Detail
Deskripsi asli dari pembuat
Get PostHog data into a canvas correctly: the host-injected `ph` SDK (loadInsight, query, capture, state, connectors, openExternal, navigate), the data hierarchy (saved insights first, typed query nodes second, inline HogQL last), verifiability (insight-backed metrics link their saved insight in PostHog; ad-hoc queries expose the exact query that ran), per-insight-type result shapes, progressive per-query loading, date-range wiring, live third-party data through the viewer's own connections (ph.connectors), and event capture from a canvas. Use whenever a canvas shows metrics, charts, tables, a
repo: PostHog/posthog
Popularitas
- Bintang GitHub
- 41k
- Peringkat
- #6842
- Lisensi
- β
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
depot-ci
41kMembantu agent Anda menyiapkan dan menjalankan alur kerja Depot CI, alternatif GitHub Actions, termasuk memigrasikan alur kerja yang ada dan membaca log eksekusi.
depot-container-builds
41kMembantu agent Anda membangun image Docker di builder jarak jauh Depot, termasuk image multi-platform, pengiriman ke registry, dan perbaikan kegagalan build.
depot-github-runners
41kMembantu agent Anda memindahkan job GitHub Actions ke runner yang dikelola Depot, memilih ukuran dan label runner, serta memecahkan masalah pengaturan runner.
editing-agents-md
41kMembantu agent Anda memutuskan apakah sebuah aturan layak masuk ke berkas AGENTS.md atau CLAUDE.md, dan menulisnya agar tetap dipatuhi tanpa membuat berkas membengkak.
Skill serupa
discrawl
394kMemungkinkan agent Anda mencari dan merangkum arsip pesan Discord lokal yang tersimpan, memeriksa seberapa baru arsipnya, dan membaca pesan langsung.
clickhouse-io
280kMembantu agent Anda mengoptimalkan query dan skema di database ClickHouse dengan praktik terbaik analitik berperforma tinggi. Gunakan saat query analitik terlalu lambat.
scientific-db-pubmed-database
280kMembantu agent Anda mencari artikel ilmiah di bidang biomedis. Berguna untuk riset yang membutuhkan informasi medis spesifik.