querying-canvas-data

Load PostHog insights and run HogQL queries inside canvas dashboards via the ph SDK.

713|118|Updated Aug 11, 2020
One-click install
npx skills add https://github.com/PostHog/posthog-foss --skill querying-canvas-data
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: querying-canvas-data
Source: https://github.com/PostHog/posthog-foss/tree/main/products/canvas/skills/querying-canvas-data
Command: npx skills add https://github.com/PostHog/posthog-foss --skill querying-canvas-data

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Canvas dashboards need live PostHog data, but the sandboxed canvas runtime blocks direct network access, so developers cannot use fetch or posthog-js to reach analytics. This Skill defines how to correctly query, render, and verify PostHog data inside a canvas using the host-injected ph bridge.

Core Features & Use Cases

  • Data hierarchy guidance: Prefer saved insights loaded by short id via ph.loadInsight, fall back to typed query nodes, and use inline HogQL only as a last resort, with every call declared in project capabilities.
  • Verifiability rules: Insight-backed metrics link to the real insight in PostHog via ph.openExternal, and ad-hoc queries disclose the exact query that ran in a modal or disclosure element.
  • Progressive loading and result shapes: Fire queries concurrently with per-query loading/error states, respect the 8 in-flight request cap, and read trends-style series versus SQL row results correctly.
  • Use Case: Build a web-analytics status board that loads saved insights per date window, renders each card as its data arrives, captures interaction events with ph.capture, and stores viewer preferences in ph.state.

Quick Start

Use the querying-canvas-data skill to build a canvas dashboard that loads my saved PostHog insights and renders their metrics with per-card loading states.

Frequently Asked Questions about querying-canvas-data

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I load PostHog data into a canvas dashboard?

Use the ph bridge from @posthog/canvas-sdk, preferably ph.loadInsight(shortId, { dateRange }) with a saved insight. Ad-hoc typed query nodes via ph.query are secondary, and inline HogQL is the last resort. Declare every insight id and inlineQueries in project capabilities.

How do I run HogQL queries from a PostHog canvas?

Call ph.query with a typed query node like { kind: "TrendsQuery" } or an inline HogQL string. Inline queries require capabilities.posthog.inlineQueries set to true, and you must compute date bounds explicitly rather than using now() or hardcoded intervals.

Can a canvas use fetch or posthog-js to reach PostHog?

No, the canvas sandbox blocks direct network access, so fetch, posthog-js, and hand-rolled clients cannot reach PostHog. The ph bridge is the only data path, with credentials held by the host. External origins must be declared in capabilities.network.origins.

Why does my canvas query fail with a runtime limits error?

The host caps a canvas at 8 in-flight data requests and rejects the ninth. Consolidate multiple metrics into one query sliced client-side, or throttle overflow behind a concurrency limiter while keeping one state per section.

How do I store per-user state in a PostHog canvas?

Use ph.state.get and ph.state.set with the user scope for viewer-private data or shared scope for team-visible values. Declare scopes in capabilities.posthog.state; values are capped at 64 KB serialized with 256 keys per scope.

Why does my trends KPI show wrong totals for unique users?

The count field sums per-interval values, which double-counts unique users active on multiple days. Set trendsFilter display to BoldNumber on the query and read aggregated_value instead for a period-unique total.