/api-analytics-posthog-analytics
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.
$ npx -y skills add agents-inc/skills --skill api-analytics-posthog-analytics --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/api-analytics-posthog-analytics
Context preview
The summary Claude sees to decide when to auto-load this skill.
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.
SKILL.md
api-analytics-posthog-analytics.SKILL.mdname: api-analytics-posthog-analytics
description: 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.
PostHog Analytics Patterns
> **Quick Guide:** Use PostHog for product analytics with structured event naming (`category:object_action`), server-side tracking for reliability, and proper user identification integrated with your authentication flow. Client-side for UI interactions, server-side for business events. Always call `reset()` on logout, never store PII in event properties, and use `captureImmediate()` or `await shutdown()` in serverless environments.
**Detailed Resources:**
- [examples/core.md](examples/core.md) - Event naming, user identification, property conventions
- [examples/client-tracking.md](examples/client-tracking.md) - React hooks, provider setup, component tracking
- [examples/server-tracking.md](examples/server-tracking.md) - posthog-node, serverless patterns, auth events
- [examples/group-analytics.md](examples/group-analytics.md) - B2B organization tracking
- [examples/privacy-gdpr.md](examples/privacy-gdpr.md) - GDPR consent, cookieless mode, PII filtering
- [reference.md](reference.md) - Decision frameworks, anti-patterns, event taxonomy
---
<critical_requirements>
CRITICAL: Before Using This Skill
> **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants)
**(You MUST call `posthog.identify()` ONLY when a user signs up or logs in - never on every page load)**
**(You MUST include the user's database ID as `distinct_id` in ALL server-side events)**
**(You MUST call `posthog.reset()` when a user logs out to unlink future events)**
**(You MUST use the `category:object_action` naming convention for all custom events)**
**(You MUST NEVER include PII (email, name, phone) in event properties - use user IDs only)**
</critical_requirements>
---
**Auto-detection:** PostHog, posthog-js, posthog-node, usePostHog, PostHogProvider, capture, identify, group analytics, product analytics, event tracking, funnel analysis
**When to use:**
- Tracking user behavior and product analytics
- Setting up conversion funnels and retention analysis
- Implementing group analytics for B2B multi-tenant apps
- Understanding feature adoption and user journeys
- A/B testing analysis (in conjunction with feature flags)
**When NOT to use:**
- Feature flag implementation (separate concern)
- Error tracking and logging (use dedicated error tracking tools)
- Infrastructure monitoring (use observability tools)
**Key patterns covered:**
- Event naming conventions (`category:object_action`)
- Property naming patterns (`object_adjective`, `is_`/`has_` booleans)
- User identification with authentication flow integration
- Client-side tracking with React hooks
- Server-side tracking with posthog-node
- Group analytics for B2B organizations
- Privacy and GDPR consent patterns
- TypeScript patterns for type-safe events
---
<philosophy>
Philosophy
PostHog analytics follows a **structured taxonomy** approach: consistent naming conventions, meaningful properties, and strategic placement (client vs server). Track what matters for product decisions, not everything.
**Core principles:**
1. **Server-side for business events** - User signups, purchases, subscriptions (reliable, not blocked) 2. **Client-side for UI interactions** - Button clicks, page views, form interactions 3. **Identify once per session** - Not on every page load 4. **Structured naming** - Makes querying and analysis possible at scale
</philosophy>
---
<patterns>
Core Patterns
Pattern 1: Event Naming Conventions
Use the **`category:object_action`** framework for consistent, queryable event names.
// category: Context (signup_flow, settings, dashboard)
// object: Component/location (password_button, pricing_page)
// action: Present-tense verb (click, submit, view)
"signup_flow:email_form_submit";
"dashboard:project_create";
"settings:billing_plan_upgrade";
// Simpler alternative: object_verb
"project_created";
"user_signed_up";
**Why good:** Category prefix groups related events in PostHog UI, enables wildcard queries like `signup_flow:*`, consistent naming makes analysis possible at scale.
**Property naming rules:**
- `object_adjective`: `project_id`, `plan_name`, `item_count`
- `is_` / `has_` for booleans: `is_first_purchase`, `has_completed_onboarding`
- `_date` / `_timestamp` suffix: `trial_end_date`, `last_login_timestamp`
See [examples/core.md](examples/core.md) for complete naming examples.
---
Pattern 2: User Identification with Authentication
Call `identify()` only on auth state change (not every render). Use database user ID as `distinct_id`. Call `reset()` on logout.
// Check _isIdentified() to prevent duplicate calls
useEffect(() => {
if (session?.user && !posthog._isIdentified()) {
posthog.identify(session.user.id, {
plan: session.user.plan ?? "free",
created_at: session.user.createdAt,
is_verified: session.user.emailVerified ?? false,
});
}
}, [session?.user]);// Always reset on logout
posthog?.capture("user_logged_out");
posthog?.reset(); // Unlink future events from this userSee [examples/core.md](examples/core.md) for full identification hook and logout handler.
---
Pattern 3: Server-Side Tracking
Track business events reliably from your backend with posthog-node.
// Serverless: use captureImmediate (guarantees HTTP completion)
await posthogServer.captureImmediate({
distinctId: user.id,
event: "subscription_created",
properties: { plan: "pro", is_annual: true },
});
// Always call shutdown before returning in serverless
await posthogServer.shutdown();**Key rules:**
1. Always include `distinctId` (u
Read more
name: api-analytics-posthog-analytics description: 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.
PostHog Analytics Patterns
> **Quick Guide:** Use PostHog for product analytics with structured event naming (`category:object_action`), server-side tracking for reliability, and proper user identification integrated with your authentication flow. Client-side for UI interactions, server-side for business events. Always call `reset()` on logout, never store PII in event properties, and use `captureImmediate()` or `await shutdown()` in serverless environments.
**Detailed Resources:**
- [examples/core.md](examples/core.md) - Event naming, user identification, property conventions
- [examples/client-tracking.md](examples/client-tracking.md) - React hooks, provider setup, component tracking
- [examples/server-tracking.md](examples/server-tracking.md) - posthog-node, serverless patterns, auth events
- [examples/group-analytics.md](examples/group-analytics.md) - B2B organization tracking
- [examples/privacy-gdpr.md](examples/privacy-gdpr.md) - GDPR consent, cookieless mode, PII filtering
- [reference.md](reference.md) - Decision frameworks, anti-patterns, event taxonomy
---
<critical_requirements>
CRITICAL: Before Using This Skill
> **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants)
**(You MUST call `posthog.identify()` ONLY when a user signs up or logs in - never on every page load)**
**(You MUST include the user's database ID as `distinct_id` in ALL server-side events)**
**(You MUST call `posthog.reset()` when a user logs out to unlink future events)**
**(You MUST use the `category:object_action` naming convention for all custom events)**
**(You MUST NEVER include PII (email, name, phone) in event properties - use user IDs only)**
</critical_requirements>
---
**Auto-detection:** PostHog, posthog-js, posthog-node, usePostHog, PostHogProvider, capture, identify, group analytics, product analytics, event tracking, funnel analysis
**When to use:**
- Tracking user behavior and product analytics
- Setting up conversion funnels and retention analysis
- Implementing group analytics for B2B multi-tenant apps
- Understanding feature adoption and user journeys
- A/B testing analysis (in conjunction with feature flags)
**When NOT to use:**
- Feature flag implementation (separate concern)
- Error tracking and logging (use dedicated error tracking tools)
- Infrastructure monitoring (use observability tools)
**Key patterns covered:**
- Event naming conventions (`category:object_action`)
- Property naming patterns (`object_adjective`, `is_`/`has_` booleans)
- User identification with authentication flow integration
- Client-side tracking with React hooks
- Server-side tracking with posthog-node
- Group analytics for B2B organizations
- Privacy and GDPR consent patterns
- TypeScript patterns for type-safe events
---
<philosophy>
Philosophy
PostHog analytics follows a **structured taxonomy** approach: consistent naming conventions, meaningful properties, and strategic placement (client vs server). Track what matters for product decisions, not everything.
**Core principles:**
1. **Server-side for business events** - User signups, purchases, subscriptions (reliable, not blocked) 2. **Client-side for UI interactions** - Button clicks, page views, form interactions 3. **Identify once per session** - Not on every page load 4. **Structured naming** - Makes querying and analysis possible at scale
</philosophy>
---
<patterns>
Core Patterns
Pattern 1: Event Naming Conventions
Use the **`category:object_action`** framework for consistent, queryable event names.
// category: Context (signup_flow, settings, dashboard) // object: Component/location (password_button, pricing_page) // action: Present-tense verb (click, submit, view) "signup_flow:email_form_submit"; "dashboard:project_create"; "settings:billing_plan_upgrade"; // Simpler alternative: object_verb "project_created"; "user_signed_up";
**Why good:** Category prefix groups related events in PostHog UI, enables wildcard queries like `signup_flow:*`, consistent naming makes analysis possible at scale.
**Property naming rules:**
- `object_adjective`: `project_id`, `plan_name`, `item_count`
- `is_` / `has_` for booleans: `is_first_purchase`, `has_completed_onboarding`
- `_date` / `_timestamp` suffix: `trial_end_date`, `last_login_timestamp`
See [examples/core.md](examples/core.md) for complete naming examples.
---
Pattern 2: User Identification with Authentication
Call `identify()` only on auth state change (not every render). Use database user ID as `distinct_id`. Call `reset()` on logout.
// Check _isIdentified() to prevent duplicate calls
useEffect(() => {
if (session?.user && !posthog._isIdentified()) {
posthog.identify(session.user.id, {
plan: session.user.plan ?? "free",
created_at: session.user.createdAt,
is_verified: session.user.emailVerified ?? false,
});
}
}, [session?.user]);// Always reset on logout
posthog?.capture("user_logged_out");
posthog?.reset(); // Unlink future events from this userSee [examples/core.md](examples/core.md) for full identification hook and logout handler.
---
Pattern 3: Server-Side Tracking
Track business events reliably from your backend with posthog-node.
// Serverless: use captureImmediate (guarantees HTTP completion)
await posthogServer.captureImmediate({
distinctId: user.id,
event: "subscription_created",
properties: { plan: "pro", is_annual: true },
});
// Always call shutdown before returning in serverless
await posthogServer.shutdown();**Key rules:**
1. Always include `distinctId` (u
Showing the first part of this file.
The official skills marketplace for Agents Inc. 150+ skills covering everything from React and Prisma to Redis, ElevenLabs, and infrastructure tooling. Pick the skills that match your stack and install them via Claude Code. Need more control?
Repo: agents-inc/skills
Other skills on agents-inc-skills.
- /ai-infrastructure-huggingface-inference
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
Open skill - /ai-infrastructure-litellm
LiteLLM proxy server setup, TypeScript client patterns via OpenAI SDK, model routing, fallbacks, load balancing, spend tracking, virtual keys, and production deployment
Open skill - /ai-infrastructure-modal
Serverless GPU compute platform for AI model deployment — web endpoints, GPU functions, model serving, and TypeScript client patterns
Open skill - /ai-infrastructure-ollama
Local LLM inference with the Ollama JavaScript client -- chat, streaming, tool calling, vision, embeddings, structured output, model management, and OpenAI-compatible endpoint
Open skill - /ai-infrastructure-replicate
Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training
Open skill - /ai-infrastructure-together-ai
Together AI SDK patterns for TypeScript — client setup, chat completions, streaming, structured output, function calling, embeddings, image generation, fine-tuning, and OpenAI-compatible endpoints
Open skill

