querying-canvas-data
Was er macht
Dieser Skill zeigt, wie eine Canvas Daten aus PostHog sicher und genau laden sollte. Er richtet sich an Entwickler, deren Canvas-Zahlen mit den Insights und Berichten übereinstimmen sollen, denen sie bereits vertrauen.
Wann du ihn nutzt
- ✓Wenn eine Canvas eine Kennzahl aus PostHog anzeigen soll.
- ✓Wenn Canvas-Zahlen nicht mit dem gespeicherten PostHog-Insight übereinstimmen, aus dem sie stammen.
- ✓Wenn eine Canvas-Kennzahl auf ihr gespeichertes Insight zurückverlinken soll.
Link zum Skill
https://github.com/PostHog/posthog/blob/master/products/canvas/skills/querying-canvas-data/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Zeig in dieser Canvas unsere wöchentlich aktiven Nutzer und stelle sicher, dass die Zahl mit unserem gespeicherten Insight übereinstimmt.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Die KI bevorzugt das Laden eines vorhandenen gespeicherten Insights, damit die Zahlen identisch mit PostHog bleiben. Typisierte Abfragen kommen danach, Inline-SQL nur als letzte Option. Dann stellt sie die Ergebnisse dar.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von 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
Häufige Fragen
Warum zuerst ein Insight speichern?
Ein gespeichertes Insight nutzt die Abfragelogik von PostHog, deshalb stimmen seine Zahlen exakt mit der Oberfläche von PostHog überein.
Kann eine Canvas rohe Abfragen ausführen?
Ja, aber das ist die letzte Option. Inline-Abfragen zeigen die genaue Abfrage, die gelaufen ist, und helfen Menschen, die Zahl zu prüfen.
Braucht eine Canvas API-Schlüssel?
Nein. Zugangsdaten bleiben in PostHog, die Canvas nutzt stattdessen die Datenbrücke.
Details
Originalbeschreibung des Autors
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
Beliebtheit
- GitHub-Sterne
- 41k
- Platz im Ranking
- #6842
- Lizenz
- —
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
depot-ci
41kBringt deinem Agenten bei, Depot-CI-Workflows einzurichten, bestehende Workflows zu migrieren und Laufprotokolle auszuwerten.
depot-container-builds
41kHilft deinem Agenten, Docker-Images auf Depot-Remote-Buildern zu bauen, mit Multi-Plattform-Images, Registry-Push und Fehlerbehebung.
depot-github-runners
41kLässt deinen Agenten GitHub-Actions-Jobs auf Depot-Runnern laufen, mit passender Runner-Größe und Labels, und hilft bei Einrichtungsfehlern.
editing-agents-md
41kHilft deinem Agenten zu entscheiden, ob eine Regel in AGENTS.md oder CLAUDE.md gehört, und sie so zu formulieren, dass sie hält.
Ähnliche Skills
discrawl
394kLässt deinen Agenten ein gespeichertes lokales Archiv von Discord-Nachrichten durchsuchen und zusammenfassen, dessen Aktualität prüfen und Direktnachrichten lesen.
clickhouse-io
280kHilft deinem Agenten, Abfragen und Schemas in ClickHouse zu optimieren. Nutzt Best Practices für schnelle Analyse-Workloads. Ideal, wenn Auswertungen zu langsam laufen.
scientific-db-pubmed-database
280kHilft deinem Agenten, wissenschaftliche Artikel im biomedizinischen Bereich zu suchen. Nützlich für Recherchen mit speziellen medizinischen Informationen.