About posthog-instrumentation
posthog-instrumentation is a skill for developers adding PostHog analytics, event tracking, and feature flags to code. It identifies the framework, checks for an existing setup, and applies suitable instrumentation patterns.
Key features
- 01Identify the project framework
- 02Check existing PostHog setup
- 03Add event tracking
- 04Implement feature flags
- 05Provide JavaScript, Python, and React examples
Use cases
- 01Adding PostHog analytics to an application
- 02Tracking user actions and business events
- 03Rolling out features with feature flags
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ posthog/ posthog-for-claude --skill posthog-instrumentationAfter installing, type/posthog-instrumentationin Claude Code to confirm it loaded.
Details
From the project READMEPostHog Instrumentation Skill
Help users add PostHog analytics, event tracking, and feature flags to their code.
When to Use
- User asks to "add PostHog" or "add analytics"
- User wants to track events or user actions
- User needs to implement feature flags
- User asks about instrumenting their code
Workflow
- Identify the framework (React, Next.js, Python, Node.js, etc.)
- Check for existing PostHog setup
- Add appropriate instrumentation
Code Patterns
JavaScript/TypeScript
// Event tracking
posthog.capture('button_clicked', { button_name: 'signup' })
// Feature flags
if (posthog.isFeatureEnabled('new-feature')) {
// Show new feature
}
// User identification
posthog.identify(userId, { email: user.email })
Python
from posthog import Posthog
posthog = Posthog(api_key='<ph_project_api_key>')
# Event tracking
posthog.capture(distinct_id='user_123', event='purchase_completed')
# Feature flags
if posthog.feature_enabled('new-feature', 'user_123'):
# Show new feature
React
import { usePostHog } from 'posthog-js/react'
function MyComponent() {
const posthog = usePostHog()
const handleClick = () => {
posthog.capture('button_clicked')
}
}
Best Practices
- Use consistent event naming (snake_case recommended)
- Include relevant properties with events
- Identify users early in their session
- Use feature flags for gradual rollouts
Comments
Markdown supported