posthog-prod-checklist
Provides a production readiness checklist for PostHog integrations to ensure robust SDK configuration and error handling.
Install
mkdir -p .claude/skills/posthog-prod-checklist && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/7839" && unzip -o skill.zip -d .claude/skills/posthog-prod-checklist && rm skill.zipInstalls to .claude/skills/posthog-prod-checklist
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Production readiness checklist for PostHog integrations: SDK configuration,Key capabilities
- →Harden PostHog SDK configuration for production
- →Implement graceful degradation for PostHog failures
- →Verify PostHog capture and flag evaluation with a health check
- →Configure serverless functions for PostHog shutdown
- →Execute pre-flight verification for PostHog deployment
- →Provide rollback procedures for PostHog deployment issues
How it works
The skill guides through configuring the PostHog SDK, implementing error handling for analytics, setting up health checks, and defining serverless function patterns. It also provides pre-deployment verification steps and rollback instructions.
Inputs & outputs
When to use posthog-prod-checklist
- →Configuring SDK production settings
- →Implementing server-side shutdown hooks
- →Verifying health check endpoints
- →Setting up production rollback procedures
About this skill
PostHog Production Checklist
Overview
Production readiness verification for PostHog integrations. Covers SDK configuration hardening, graceful degradation when PostHog is unavailable, health check endpoints, proper shutdown hooks for serverless, and rollback procedures.
Prerequisites
- PostHog integration tested in staging
- Production PostHog project with
phc_key - Personal API key (
phx_) for server-side features - Deployment pipeline configured
Instructions
Pre-Deployment Checklist
SDK Configuration:
-
api_hostset to correct region (us.i.posthog.comoreu.i.posthog.com) -
capture_pageview: falseif using SPA with manual pageview tracking -
capture_pageleave: truefor session duration accuracy - Reverse proxy configured to bypass ad blockers (see
posthog-sdk-patterns) -
posthog.debug()disabled in production (guarded byNODE_ENV) -
autocaptureconfigured to exclude noisy elements
Server-Side:
-
posthog.shutdown()called in SIGTERM handler and serverless function cleanup -
personalApiKeyset for local flag evaluation (not just project key) -
flushAtandflushIntervaltuned (default 20/10s is fine for most apps)
Security:
- Personal API key (
phx_) never in client bundles or NEXT_PUBLIC_ vars -
.envfiles in.gitignore - Separate PostHog project per environment
Step 1: Production SDK Configuration
// lib/posthog-production.ts
import { PostHog } from 'posthog-node';
const posthog = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
host: process.env.POSTHOG_HOST || 'https://us.i.posthog.com',
personalApiKey: process.env.POSTHOG_PERSONAL_API_KEY,
flushAt: 20,
flushInterval: 10000,
requestTimeout: 10000,
maxRetries: 3,
});
// Graceful shutdown
async function shutdown() {
await posthog.shutdown();
process.exit(0);
}
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
Step 2: Graceful Degradation
// PostHog should never break your app — wrap all calls
function safeCapture(distinctId: string, event: string, properties?: Record<string, any>) {
try {
posthog.capture({ distinctId, event, properties });
} catch (error) {
// Log but never throw — analytics should not crash your app
console.error('[PostHog] Capture failed:', (error as Error).message);
}
}
async function safeGetFlag(flagKey: string, userId: string, defaultValue: boolean = false): Promise<boolean> {
try {
const result = await posthog.isFeatureEnabled(flagKey, userId);
return result ?? defaultValue;
} catch (error) {
console.error('[PostHog] Flag evaluation failed:', (error as Error).message);
return defaultValue; // Always return safe default
}
}
Step 3: Health Check Endpoint
// api/health.ts (Next.js API route or Express handler)
export async function GET() {
const checks: Record<string, { status: string; latencyMs?: number }> = {};
// PostHog capture test
const captureStart = performance.now();
try {
posthog.capture({
distinctId: 'healthcheck',
event: '$healthcheck',
properties: { test: true },
});
await posthog.flush();
checks.posthog_capture = {
status: 'ok',
latencyMs: Math.round(performance.now() - captureStart),
};
} catch {
checks.posthog_capture = { status: 'degraded' };
}
// PostHog flag evaluation test
const flagStart = performance.now();
try {
await posthog.getAllFlags('healthcheck');
checks.posthog_flags = {
status: 'ok',
latencyMs: Math.round(performance.now() - flagStart),
};
} catch {
checks.posthog_flags = { status: 'degraded' };
}
const overall = Object.values(checks).every(c => c.status === 'ok') ? 'healthy' : 'degraded';
return Response.json({ status: overall, checks }, { status: overall === 'healthy' ? 200 : 503 });
}
Step 4: Serverless Function Pattern
// For Vercel Edge Functions, AWS Lambda, etc.
import { PostHog } from 'posthog-node';
export async function handler(request: Request) {
// Create client per invocation in serverless (or use module-level singleton)
const posthog = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
host: 'https://us.i.posthog.com',
flushAt: 1, // Flush immediately in serverless
flushInterval: 0, // Don't wait
});
try {
posthog.capture({
distinctId: getUserId(request),
event: 'api_called',
properties: { endpoint: new URL(request.url).pathname },
});
const result = await doWork(request);
return Response.json(result);
} finally {
// CRITICAL: Always flush before function exits
await posthog.shutdown();
}
}
Step 5: Pre-Flight Verification
set -euo pipefail
# 1. Verify PostHog is reachable from production
curl -sf "https://us.i.posthog.com/healthz" && echo "PostHog: OK" || echo "PostHog: UNREACHABLE"
# 2. Verify capture works
curl -s -X POST 'https://us.i.posthog.com/capture/' \
-H 'Content-Type: application/json' \
-d "{\"api_key\":\"$NEXT_PUBLIC_POSTHOG_KEY\",\"event\":\"deploy_preflight\",\"distinct_id\":\"deploy\"}" | jq .
# 3. Verify feature flags load
curl -s -X POST 'https://us.i.posthog.com/decide/?v=3' \
-H 'Content-Type: application/json' \
-d "{\"api_key\":\"$NEXT_PUBLIC_POSTHOG_KEY\",\"distinct_id\":\"deploy-check\"}" | \
jq '{flags_count: (.featureFlags | length), session_recording: (.sessionRecording != false)}'
# 4. Verify admin API (if using server-side features)
curl -sf "https://app.posthog.com/api/projects/$POSTHOG_PROJECT_ID/" \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" | jq '.name' && echo "Admin API: OK"
Error Handling
| Alert | Trigger | Severity | Action |
|---|---|---|---|
| PostHog capture failing | Error rate > 1% | P3 | Check API host, verify key |
| Flag evaluation slow | p95 > 500ms | P2 | Enable local evaluation with personalApiKey |
| Events not appearing | Zero events for 30min | P2 | Check shutdown() is called, verify flush |
| Admin API 401 | Personal key rejected | P1 | Rotate key in PostHog settings |
Rollback Procedure
set -euo pipefail
# Quick rollback if PostHog causes issues
# Option 1: Disable PostHog via env var
kubectl set env deployment/app POSTHOG_ENABLED=false
kubectl rollout restart deployment/app
# Option 2: Roll back deployment
kubectl rollout undo deployment/app
kubectl rollout status deployment/app
Output
- Production-hardened PostHog SDK configuration
- Graceful degradation wrappers (never crash on analytics failure)
- Health check endpoint verifying capture and flag evaluation
- Serverless shutdown pattern
- Pre-flight verification commands
Resources
Next Steps
For version upgrades, see posthog-upgrade-migration.
When not to use it
- →When PostHog integration is not tested in staging
- →When a production PostHog project with `phc_` key is unavailable
- →When a personal API key (`phx_`) for server-side features is not set
Prerequisites
Limitations
- →Requires a PostHog integration tested in staging
- →Requires a production PostHog project with a `phc_` key
- →Requires a personal API key (`phx_`) for server-side features
How it compares
This skill provides a structured, step-by-step checklist for PostHog production readiness, unlike a manual deployment that might miss critical configurations or error handling.
Compared to similar skills
posthog-prod-checklist side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| posthog-prod-checklist (this skill) | 1 | 25d | Caution | Intermediate |
| build-macos-apps | 70 | 8mo | Review | Intermediate |
| cloudflare-manager | 25 | 9mo | Review | Intermediate |
| railway-cli-management | 9 | 8mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by jeremylongshore
View all by jeremylongshore →You might also like
build-macos-apps
glittercowboy
Build professional native macOS apps in Swift with SwiftUI and AppKit. Full lifecycle - build, debug, test, optimize, ship. CLI-only, no Xcode.
cloudflare-manager
qdhenry
Comprehensive Cloudflare account management for deploying Workers, KV Storage, R2, Pages, DNS, and Routes. Use when deploying cloudflare services, managing worker containers, configuring KV/R2 storage, or setting up DNS/routing. Requires CLOUDFLARE_API_KEY in .env and Bun runtime with dependencies installed.
railway-cli-management
CaptainCrouton89
Deploy, manage services, view logs, and configure Railway infrastructure. Use when deploying to Railway, managing environment variables, viewing deployment logs, scaling services, or managing volumes.
unity-editor-toolkit
Dev-GOM
Automate and control Unity Editor with 500+ commands, real-time WebSocket communication, and SQLite integration for efficient game development.
miniprogram-development
TencentCloudBase
WeChat Mini Program development rules. Use this skill when developing WeChat mini programs, integrating CloudBase capabilities, and deploying mini program projects.
azure-functions
aj-geddes
Create serverless functions on Azure with triggers, bindings, authentication, and monitoring. Use for event-driven computing without managing infrastructure.