본문으로 건너뛰기
cccskills
무료GitHub에 공개

api-analytics-setup-posthog

PostHog analytics and feature flags setup

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(5)

  • SKILL.md7.3 KB
  • examples/core.md5.9 KB
  • examples/server.md3.7 KB
  • metadata.yaml367 B
  • reference.md1.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

PostHog Analytics & Feature Flags Setup

Quick Guide: One-time setup for PostHog analytics and feature flags. Covers posthog-js client provider, posthog-node server client, and environment variables. PostHog handles both analytics AND feature flags with a generous free tier (1M events + 1M flag requests/month).


<critical_requirements>

CRITICAL: Before Using This Skill

(You MUST initialize posthog-js only in a client/browser context - it requires browser APIs like window and localStorage)

(You MUST call posthog.shutdown(), posthog.flush(), or use captureImmediate() after server-side event capture to prevent lost events)

(You MUST use defaults: '2026-01-30' for automatic SPA page tracking and latest recommended behaviors)

</critical_requirements>


Auto-detection: PostHog setup, posthog-js, posthog-node, PostHogProvider, analytics setup, feature flags setup, event tracking setup, posthog.init

When to use:

  • Initial PostHog setup in a project
  • Configuring PostHogProvider for client-side analytics
  • Setting up posthog-node for server-side/API route event capture
  • Configuring environment variables for PostHog

When NOT to use:

  • Event tracking patterns after setup (use analytics event tracking skill)
  • Feature flag usage patterns (use feature flags skill)
  • Complex multi-environment setups with separate staging/production projects

Key patterns covered:

  • Client-side setup with PostHogProvider or framework initialization hook
  • Server-side setup with posthog-node
  • Environment variables (client vs server prefix)
  • User identification and reset flows
  • Serverless flush patterns (captureImmediate vs flush)

Detailed Resources:


<philosophy>

Philosophy

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 and feature flag services.

Core principles:

  1. One platform for analytics + feature flags - Reduces tool sprawl and cost
  2. Usage-based pricing - Pay for what you use, not per-project
  3. Autocapture by default - Automatic event tracking reduces manual instrumentation
  4. Server and client SDKs - Full coverage for SSR and client-side apps

When to use PostHog:

  • Need both analytics and feature flags in one platform
  • Want generous free tier (1M events + 1M flag requests/month)
  • Prefer open-source with self-host option
  • Building product analytics (funnels, retention, sessions)

When NOT to use PostHog:

  • Need advanced A/B testing with statistical rigor
  • Require real-time event streaming
  • Already have established analytics + flag tools
</philosophy>
<patterns>

Core Patterns

Pattern 1: PostHog Project Structure

Use a single PostHog organization for your apps. One org pools billing. Use separate projects per app, or one project with custom properties to filter.

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)

Why good: Single org pools billing across all projects, usage-based pricing, 6 projects included on paid tier


Pattern 2: Client-Side Setup

Install posthog-js and configure a provider or use your framework's client-side initialization hook.

Key config options: defaults: "2026-01-30" enables recommended behaviors, person_profiles: "identified_only" reduces costs.

See examples/core.md for full implementation of both approaches.

Why good: defaults date enables automatic SPA page/leave tracking, person_profiles: "identified_only" reduces event costs, debug mode in development aids troubleshooting


Pattern 3: Server-Side Setup with posthog-node

Install posthog-node and create a singleton for server-side event capture.

Serverless flush options:

  • captureImmediate() - simplest, awaits HTTP request directly (one request per event)
  • capture() + await flush() - batched, requires explicit flush before response returns

See examples/server.md for singleton setup, API route usage, and the flush anti-pattern.

Why good: Singleton prevents multiple client instances, flushInterval/flushAt configure batching, captureImmediate simplifies serverless usage

</patterns>

<red_flags>

RED FLAGS

  • Initializing posthog-js on the server (requires browser APIs - will crash)
  • No flush() or captureImmediate() after server-side capture in serverless environments (events silently lost)
  • Client-side env vars not exposed to the browser bundle (check your framework's prefix convention)
  • Hardcoding API keys in source code instead of environment variables
  • Missing posthog.reset() on sign out (user identity bleeds to next session)
  • Not using defaults date option (manual pageview tracking required, misses recommended behaviors)
  • Not calling posthog.identify() after authentication (anonymous and authenticated sessions remain unlinked)
  • No person_profiles: 'identified_only' option (unnecessary anonymous profiles created, higher costs)
  • Not wrapping app with PostHogProvider when using hooks (hooks return null)
  • Forgetting to add environment variables to deployment platform (events fail silently)
  • Using different PostHog projects for dev/prod without realizing (separate data)

Gotchas & Edge Cases:

  • posthog-js must be initialized after window is available (hence useEffect or a client-side initialization hook)
  • Server-side SDK does NOT auto-flush like the client - you must explicitly call flush(), shutdown(), or use captureImmediate()
  • captureImmediate() is simpler for serverless but sends one HTTP request per event (no batching)
  • Free tier resets monthly (1M events then stops capturing until next month)
  • person_profiles: 'identified_only' reduces costs but means no anonymous user profiles are created
  • When using auto-initialization hooks, config values remain fixed for the session - bootstrapping only works if flags are evaluated on the server before render

</red_flags>


<critical_reminders>

CRITICAL REMINDERS

(You MUST initialize posthog-js only in a client/browser context - it requires browser APIs like window and localStorage)

(You MUST call posthog.shutdown(), posthog.flush(), or use captureImmediate() after server-side event capture to prevent lost events)

(You MUST use defaults: '2026-01-30' for automatic SPA page tracking and latest recommended behaviors)

Failure to follow these rules will cause lost analytics events, broken tracking, or security vulnerabilities.

</critical_reminders>


Sources

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Hugging Face Inference SDK patterns for TypeScript/Node.js — InferenceClient setup, chat completion, text generation, streaming, embeddings, image generation, audio transcription, translation, summarization, and Inference Endpoints

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

agents-inc/skills252026년 10월 17일 업데이트

LiteLLM proxy server setup, TypeScript client patterns via OpenAI SDK, model routing, fallbacks, load balancing, spend tracking, virtual keys, and production deployment

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

agents-inc/skills252026년 10월 17일 업데이트

Serverless GPU compute platform for AI model deployment — web endpoints, GPU functions, model serving, and TypeScript client patterns

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

agents-inc/skills252026년 10월 17일 업데이트

Local LLM inference with the Ollama JavaScript client -- chat, streaming, tool calling, vision, embeddings, structured output, model management, and OpenAI-compatible endpoint

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

agents-inc/skills252026년 10월 17일 업데이트

Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

agents-inc/skills252026년 10월 17일 업데이트

Together AI SDK patterns for TypeScript — client setup, chat completions, streaming, structured output, function calling, embeddings, image generation, fine-tuning, and OpenAI-compatible endpoints

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

agents-inc/skills252026년 10월 17일 업데이트

agents-inc의 스킬 모두 보기

이 스킬의 문제 신고