con un clic
api-analytics-setup-posthog
PostHog analytics and feature flags setup
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Menú
PostHog analytics and feature flags setup
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Basado en la clasificación ocupacional SOC
Flexible data science analytics for any dataset. Auto-discovers schema, recommends charts, exports to create-figure. Works with JSONL, JSON, CSV from any source.
Use when you have CSV/Excel data files and need PM insights (retention, funnel, segmentation) via Python analysis.
Strategische Markenportfolio-Planung für Luxus-Modehaeuser: Mandant will Marken in DE/EU/international schützen oder Portfolio optimieren. Normen: §§ 32 ff. MarkenG, Art. 32 ff. UMV (EU) 2017/1001, Madrid-Protokoll (WIPO). Prüfraster: Nizza-Klassen (3/14/18/25/35), Multi-Class-Strategie, Prioritaets-Kaskade, Kostenoptimierung, Anmeldezeitpunkt. Output Marken-Portfolio-Plan, Anmelde-Empfehlung je Territorium, Kostenprojektion. Abgrenzung: Einzelne Anmeldung DPMA siehe wortmarke-anmeldung-dpma; Madrid-Protokoll Details siehe madrid-protokoll-und-internationale-registrierung.
Generate comprehensive anomaly detection report with Excel deliverables. Discovers data quality issues without requiring configuration.
Detect data anomalies in Datarails Finance OS tables. Finds outliers, missing values, duplicates, and data quality issues.
PostHog event tracking, user identification, group analytics for B2B, GDPR consent patterns. Use when implementing product analytics, tracking user behavior, setting up funnels, or configuring privacy-compliant tracking.
| name | api-analytics-setup-posthog |
| description | PostHog analytics and feature flags setup |
Quick Guide: One-time setup for PostHog in Next.js App Router monorepo. Covers
posthog-jsclient provider,posthog-nodeserver client, environment variables, and Vercel deployment. PostHog handles both analytics AND feature flags with a generous free tier (1M events + 1M flag requests/month).
<critical_requirements>
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST use NEXT_PUBLIC_ prefix for client-side PostHog environment variables)
(You MUST create PostHogProvider as a 'use client' component - posthog-js requires browser APIs)
(You MUST call posthog.shutdown() or posthog.flush() after server-side event capture to prevent lost events)
(You MUST use defaults: '2025-11-30' or capture_pageview: 'history_change' for automatic SPA page tracking)
(You MUST use a single PostHog organization for all monorepo apps - projects are usage-based, not per-project pricing)
</critical_requirements>
Auto-detection: PostHog setup, posthog-js, posthog-node, PostHogProvider, analytics setup, feature flags setup, event tracking setup, NEXT_PUBLIC_POSTHOG_KEY
When to use:
When NOT to use:
backend/analytics.md for that)backend/feature-flags.md for that)Key patterns covered:
Detailed Resources:
PostHog is a product analytics + feature flags platform that consolidates multiple tools into one. It's open-source, can be self-hosted, and has a generous free tier. For solo developers and small teams, PostHog eliminates the need for separate analytics (Mixpanel/Amplitude) and feature flag (LaunchDarkly) services.
Core principles:
When to use PostHog:
When NOT to use PostHog:
Create a single PostHog organization for your monorepo. You can either use one project for all apps or create separate projects per app.
PostHog Organization: "Your Company"
├── Project: "Main App" (or separate per app)
│ ├── API Key: phc_xxx
│ └── Host: https://us.i.posthog.com (or eu.i.posthog.com)
# Example API key format
phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Why good: Single organization pools billing across all projects, 6 projects included on paid tier, usage-based pricing means you're not penalized for multiple apps
Install dependencies and configure for Next.js App Router.
# Install client-side SDK
bun add posthog-js
# apps/client-next/.env.local
# PostHog Configuration
NEXT_PUBLIC_POSTHOG_KEY=phc_your_project_api_key_here
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
Next.js 15.3+: Use instrumentation-client.js (simpler, recommended)
Next.js < 15.3: Use PostHogProvider component (traditional approach)
See examples/core.md for both approaches with full implementation examples.
Why good: defaults: "2025-11-30" enables automatic SPA page/leave tracking, person_profiles: "identified_only" reduces event costs, debug mode in development aids troubleshooting
Install and configure the Node.js SDK for server-side event capture in API routes and Hono middleware.
# Install server-side SDK
bun add posthog-node
# apps/client-next/.env.local (or apps/server/.env.local)
# Server-side PostHog (no NEXT_PUBLIC_ prefix needed)
POSTHOG_API_KEY=phc_your_project_api_key_here
POSTHOG_HOST=https://us.i.posthog.com
Create a server client singleton for reuse across API routes. See examples/server.md for the full implementation including API route and Hono middleware examples.
Option 1: Use captureImmediate() - simplest, awaits HTTP request directly
Option 2: Use capture() + await flush() - batched, requires explicit flush
Why good: Singleton prevents multiple client instances, flushInterval/flushAt configure batching, shutdown function for graceful cleanup, captureImmediate for simple serverless usage
<critical_reminders>
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST use NEXT_PUBLIC_ prefix for client-side PostHog environment variables)
(You MUST create PostHogProvider as a 'use client' component - posthog-js requires browser APIs)
(You MUST call posthog.shutdown() or posthog.flush() after server-side event capture to prevent lost events)
(You MUST use defaults: '2025-11-30' or capture_pageview: 'history_change' for automatic SPA page tracking)
(You MUST use a single PostHog organization for all monorepo apps - projects are usage-based, not per-project pricing)
Failure to follow these rules will cause lost analytics events, broken tracking, or security vulnerabilities.
</critical_reminders>