| name | posthog-install-auth |
| description | Install and configure PostHog SDKs with authentication.
Use when setting up posthog-js (browser), posthog-node (server),
or configuring API keys for a new PostHog integration.
Trigger: "install posthog", "setup posthog", "posthog auth",
"configure posthog API key", "posthog init".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*), Bash(pip:*), Grep |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","posthog","api","authentication"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
PostHog Install & Auth
Overview
Install PostHog SDKs and configure authentication. PostHog uses two key types: Project API Key (phc_...) for event capture (public, safe for frontend) and Personal API Key (phx_...) for private API endpoints (never expose to clients).
Prerequisites
- Node.js 20+ or Python 3.10+
- PostHog account at app.posthog.com
- Project API key from Project Settings > Project API Key
- Personal API key from Settings > Personal API Keys (for server-side admin)
Instructions
Step 1: Install the SDK
set -euo pipefail
npm install posthog-js
npm install posthog-node
pip install posthog
Step 2: Configure Environment Variables
NEXT_PUBLIC_POSTHOG_KEY=phc_your_project_api_key
POSTHOG_HOST=https://us.i.posthog.com
POSTHOG_PERSONAL_API_KEY=phx_your_personal_key
POSTHOG_PROJECT_ID=12345
Step 3: Initialize Browser SDK (posthog-js)
import posthog from 'posthog-js';
export function initPostHog() {
if (typeof window === 'undefined') return;
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
api_host: process.env. || ,
: ,
: ,
: ,
: ,
: {
(process.. === ) {
ph.();
}
},
});
}