Query PostHog data directly from Grafana using HogQL (PostHog's SQL dialect).
- HogQL query editor with Monaco SQL highlighting
- Time range macros (
$__timeFrom,$__timeTo) integrate with Grafana's time picker - Grafana dashboard variable support
- Go backend — API keys stored encrypted, queries execute server-side
- Alerting support
grafana-cli \
--pluginUrl https://github.com/mewc/posthog-grafana-plugin/releases/download/v1.0.0/chartcastr-posthog-datasource-v1.0.0.zip \
plugins install chartcastr-posthog-datasourceSince this plugin is not yet signed via the Grafana catalog, you need to allow it explicitly.
Add to grafana.ini:
[plugins]
allow_loading_unsigned_plugins = chartcastr-posthog-datasourceOr as an environment variable (useful for Docker/Kubernetes):
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=chartcastr-posthog-datasourceRestart Grafana after installing.
- Download the latest zip from Releases
- Extract into your Grafana plugins directory (default:
/var/lib/grafana/plugins/) - Allow the unsigned plugin (see above)
- Restart Grafana
- Connections → Data sources → Add data source → search "PostHog"
- Configure:
- PostHog Instance — US Cloud, EU Cloud, or Custom (self-hosted) URL
- Project ID — found in PostHog → Settings → Project
- API Key — a Personal API Key (PostHog → Settings → Personal API Keys). This is not the project API key.
- Save & Test — should show a green checkmark
SELECT
toStartOfDay(timestamp) AS day,
count() AS event_count
FROM events
WHERE timestamp >= $__timeFrom AND timestamp < $__timeTo
GROUP BY day
ORDER BY daySELECT
event,
count() AS count
FROM events
WHERE timestamp >= $__timeFrom AND timestamp < $__timeTo
GROUP BY event
ORDER BY count DESC
LIMIT 10SELECT
toStartOfDay(timestamp) AS day,
count(DISTINCT distinct_id) AS unique_users
FROM events
WHERE timestamp >= $__timeFrom AND timestamp < $__timeTo
GROUP BY day
ORDER BY day| Macro | Replaced with |
|---|---|
$__timeFrom |
Start of selected Grafana time range, e.g. '2024-01-15 10:30:00' |
$__timeTo |
End of selected Grafana time range |
- Node.js >= 22
- Go >= 1.23
- Mage —
go install github.com/magefile/mage@latest - Docker & Docker Compose
# Install dependencies
npm install && go mod tidy
# Build frontend + backend
npm run build && mage -v buildAll
# Start Grafana with the plugin loaded
docker compose up --buildOpen http://localhost:3000 — anonymous admin access is enabled in dev mode.
npm run dev # terminal 1: frontend watcher
docker compose up --build # terminal 2: Grafana + backend auto-rebuildThe Docker Compose setup uses supervisord to watch for backend changes, rebuild via mage, and attach a Delve debugger on port 2345.
The plugin is auto-provisioned via provisioning/datasources/default.yaml. Set these env vars before docker compose up to skip manual configuration:
export POSTHOG_URL=https://us.posthog.com # or eu.posthog.com, or self-hosted
export POSTHOG_PROJECT_ID=12345
export POSTHOG_API_KEY=phx_your_personal_api_keyOr just configure the datasource manually in the Grafana UI.
npm run typecheck # TypeScript type checking
npm run lint # ESLint
npm run test:ci # Jest (frontend)
go test ./pkg/... # Go (backend)Push a version tag to trigger the automated release workflow:
git tag v1.0.0
git push origin v1.0.0The release workflow builds frontend + backend, packages a zip, and creates a GitHub Release. Users install with:
grafana-cli --pluginUrl <zip-url> plugins install chartcastr-posthog-datasourcenpm run build && mage -v buildAll
cp -r dist chartcastr-posthog-datasource
zip -r chartcastr-posthog-datasource-1.0.0.zip chartcastr-posthog-datasource/Install the zip on any Grafana instance by extracting into the plugins directory and setting allow_loading_unsigned_plugins.
Signing is not required for self-hosted Grafana with allow_loading_unsigned_plugins. It is only required if you want to:
- Distribute without requiring users to modify
grafana.ini - Submit to the Grafana plugin catalog
To sign, you need a free Grafana Cloud account (just for the signing token — no Grafana Cloud instance needed):
- Sign up at grafana.com
- Go to My Account → Security → Access Policies
- Create a policy with scope
plugins:write, then create a token - Add the token as a GitHub repo secret:
GRAFANA_ACCESS_POLICY_TOKEN
The release workflow will automatically sign the plugin when this secret is present.
To publish to the official Grafana plugin catalog (so users can install via grafana-cli plugins install without a URL):
- Ensure the repo is public and the plugin is signed (see above)
- Validate:
npx -y @grafana/plugin-validator@latest -sourceCodeUri https://github.com/mewc/posthog-grafana-plugin chartcastr-posthog-datasource-1.0.0.zip - Submit at grafana.com → Org Settings → My Plugins → Submit New Plugin
- Provide the release zip URL, source repo URL, and SHA1 hash (
sha1sum *.zip) - Grafana team reviews (automated checks + manual code review)
Apache-2.0