querying-canvas-data
Ce qu’il fait
Cette skill montre comment un canvas doit charger les données PostHog de façon sûre et exacte. Elle s'adresse aux créateurs qui veulent que les chiffres de leur canvas correspondent aux insights et rapports auxquels ils se fient.
Quand l’utiliser
- ✓Quand un canvas doit afficher une métrique issue de PostHog.
- ✓Quand les chiffres d'un canvas ne correspondent pas à l'insight PostHog dont ils proviennent.
- ✓Quand vous voulez qu'une métrique de canvas renvoie vers son insight enregistré.
Lien du skill
https://github.com/PostHog/posthog/blob/master/products/canvas/skills/querying-canvas-data/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Affiche nos utilisateurs actifs hebdomadaires dans ce canvas, et vérifie que le chiffre correspond à notre insight enregistré.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
L'IA privilégie le chargement d'un insight enregistré existant, ce qui garde les chiffres identiques à ceux de PostHog. Elle utilise ensuite des requêtes typées, et le SQL en ligne seulement en dernier recours, puis affiche les résultats.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes
Pourquoi enregistrer d'abord un insight ?
Un insight enregistré utilise la logique de requête de PostHog, donc ses chiffres correspondent exactement à ceux de l'interface PostHog.
Un canvas peut-il exécuter des requêtes brutes ?
Oui, mais c'est la dernière option. Les requêtes en ligne montrent la requête exacte exécutée, ce qui aide à vérifier le chiffre.
Un canvas a-t-il besoin de clés API ?
Non. Les identifiants restent dans PostHog, et le canvas passe par le pont de données.
Détails
Description originale de l’auteur
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
Popularité
- Étoiles GitHub
- 41k
- Position au classement
- #6842
- Licence
- —
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
depot-ci
41kAide votre agent à configurer et exécuter des workflows Depot CI, alternative à GitHub Actions, en migrant les workflows existants et en lisant les journaux.
depot-container-builds
41kAide votre agent à construire des images Docker sur les constructeurs distants de Depot, y compris les images multiplateformes et la correction des échecs.
depot-github-runners
41kAide votre agent à faire tourner les jobs GitHub Actions sur les machines gérées par Depot, à choisir la taille des runners et leurs labels, et à résoudre les problèmes de configuration.
editing-agents-md
41kAide votre agent à décider si une règle doit figurer dans un fichier AGENTS.md ou CLAUDE.md, et à la rédiger pour qu'elle soit suivie sans alourdir le fichier.
Skills similaires
discrawl
394kPermet à votre agent de rechercher et de résumer une archive locale des messages Discord, de vérifier sa fraîcheur et de lire les messages privés.
clickhouse-io
280kAide votre agent à optimiser requêtes et schémas ClickHouse selon les bonnes pratiques pour les analyses hautes performances. À utiliser si les requêtes sont trop lentes.
scientific-db-pubmed-database
280kAide votre agent à rechercher des articles scientifiques dans le domaine biomédical. Utile pour les recherches nécessitant des informations médicales précises.