posthog-hello-world
A quick-start guide to implementing basic PostHog functionality with minimal boilerplate.
Install
mkdir -p .claude/skills/posthog-hello-world && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/8368" && unzip -o skill.zip -d .claude/skills/posthog-hello-world && rm skill.zipInstalls to .claude/skills/posthog-hello-world
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.
Create a minimal working PostHog example with event capture, identify,Key capabilities
- →Capture custom events via Node.js and browser SDKs
- →Identify users with persistent properties
- →Evaluate feature flags for conditional logic
- →Perform batch event capture via HTTP API
- →Associate users with company groups
How it works
The skill provides minimal code templates for initializing SDKs, capturing events, identifying users, and checking feature flags.
Inputs & outputs
When to use posthog-hello-world
- →Initialize PostHog in a new project
- →Send a first test event to verify setup
- →Test feature flag evaluation patterns
- →Demonstrate basic SDK usage for teams
About this skill
PostHog Hello World
Overview
Minimal working examples demonstrating the three core PostHog operations: capturing events, identifying users, and evaluating feature flags. Covers both browser (posthog-js) and server (posthog-node) SDKs.
Prerequisites
- Completed
posthog-install-authsetup - Project API key (
phc_...) configured posthog-jsand/orposthog-nodeinstalled
Instructions
Step 1: Capture Your First Event (Node.js)
// hello-posthog.ts
import { PostHog } from 'posthog-node';
const posthog = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
host: 'https://us.i.posthog.com',
});
async function main() {
// 1. Capture a custom event
posthog.capture({
distinctId: 'user-123',
event: 'hello_posthog',
properties: {
greeting: 'Hello from posthog-node!',
source: 'hello-world-skill',
timestamp: new Date().toISOString(),
},
});
console.log('Event captured: hello_posthog');
// 2. Identify a user with properties
posthog.identify({
distinctId: 'user-123',
properties: {
email: '[email protected]',
name: 'Dev User',
plan: 'free',
},
});
console.log('User identified: user-123');
// 3. Check a feature flag
const flagValue = await posthog.getFeatureFlag('my-feature-flag', 'user-123');
console.log(`Feature flag "my-feature-flag": ${flagValue}`);
// 4. Flush and shutdown (required in scripts/serverless)
await posthog.shutdown();
console.log('Done — check app.posthog.com Activity tab');
}
main().catch(console.error);
Step 2: Browser Hello World (posthog-js)
// In a React component or vanilla JS
import posthog from 'posthog-js';
// Initialize (call once at app startup)
posthog.init('phc_your_project_key', {
api_host: 'https://us.i.posthog.com',
loaded: () => console.log('PostHog loaded'),
});
// Capture a custom event
posthog.capture('button_clicked', {
button_name: 'signup',
page: window.location.pathname,
});
// Identify the user after login
posthog.identify('user-123', {
email: '[email protected]',
plan: 'pro',
});
// Check a feature flag
if (posthog.isFeatureEnabled('new-checkout')) {
console.log('New checkout flow is enabled');
}
// Associate user with a company (group analytics)
posthog.group('company', 'company-456', {
name: 'Acme Corp',
plan: 'enterprise',
});
Step 3: Python Hello World
import posthog
posthog.project_api_key = 'phc_your_project_key'
posthog.host = 'https://us.i.posthog.com'
# Capture event
posthog.capture('user-123', 'hello_posthog', {
'greeting': 'Hello from Python!',
})
# Identify user
posthog.identify('user-123', {
'email': '[email protected]',
'plan': 'free',
})
# Feature flag
is_enabled = posthog.feature_enabled('my-flag', 'user-123')
print(f'Flag enabled: {is_enabled}')
Step 4: Raw HTTP API (No SDK)
set -euo pipefail
# Capture event via POST to /capture/
curl -X POST 'https://us.i.posthog.com/capture/' \
-H 'Content-Type: application/json' \
-d '{
"api_key": "phc_your_project_key",
"event": "hello_posthog",
"distinct_id": "user-123",
"properties": {
"greeting": "Hello from curl!"
}
}'
# Batch capture multiple events
curl -X POST 'https://us.i.posthog.com/batch/' \
-H 'Content-Type: application/json' \
-d '{
"api_key": "phc_your_project_key",
"batch": [
{"event": "page_viewed", "distinct_id": "user-123", "properties": {"page": "/home"}},
{"event": "button_clicked", "distinct_id": "user-123", "properties": {"button": "cta"}}
]
}'
Error Handling
| Error | Cause | Solution |
|---|---|---|
| Events not in dashboard | Not flushed | Call await posthog.shutdown() or posthog.flush() |
posthog.init silently fails | Wrong API host | Use us.i.posthog.com (not app.posthog.com) |
Feature flag returns undefined | Flag not created yet | Create flag in PostHog dashboard first |
identify not linking | Different distinct_id | Frontend and backend must use the same distinct_id |
| Python events missing | No flush before exit | posthog.shutdown() or posthog.flush() at end |
Output
- Working event capture in PostHog Activity tab
- User identified with properties in Persons view
- Feature flag evaluation result logged
- Console output confirming each operation
Resources
Next Steps
Proceed to posthog-local-dev-loop for development workflow setup.
When not to use it
- →When failing to flush events in serverless scripts
- →When using incorrect API host URLs
Prerequisites
Limitations
- →Feature flags return undefined if not created in dashboard
- →Python events require explicit flush before exit
How it compares
It provides a verified baseline for integration compared to generic documentation examples.
Compared to similar skills
posthog-hello-world side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| posthog-hello-world (this skill) | 0 | 27d | Caution | Beginner |
| develop-ai-functions-example | 5 | 6mo | Review | Intermediate |
| adk-engineer | 3 | 27d | Review | Advanced |
| posthog-local-dev-loop | 1 | 27d | 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
develop-ai-functions-example
vercel
Develop examples for AI SDK functions. Use when creating, running, or modifying examples under examples/ai-functions/src to validate provider support, demonstrate features, or create test fixtures.
adk-engineer
jeremylongshore
Execute software engineer specializing in creating production-ready ADK agents with best practices, code structure, testing, and deployment automation. Use when asked to "build ADK agent", "create agent code", or "engineer ADK application". Trigger with relevant phrases based on skill purpose.
posthog-local-dev-loop
jeremylongshore
Configure PostHog local development with hot reload and testing. Use when setting up a development environment, configuring test workflows, or establishing a fast iteration cycle with PostHog. Trigger with phrases like "posthog dev setup", "posthog local development", "posthog dev environment", "develop with posthog".
langsmith-evaluator
dhar174
INVOKE THIS SKILL when building evaluation pipelines for LangSmith. Covers three core components: (1) Creating Evaluators - LLM-as-Judge, custom code; (2) Defining Run Functions - how to capture outputs and trajectories from your agent; (3) Running Evaluations - locally with evaluate() or auto-run v
mcp-builder
anthropics
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
dependency-upgrade
wshobson
Manage major dependency version upgrades with compatibility analysis, staged rollout, and comprehensive testing. Use when upgrading framework versions, updating major dependencies, or managing breaking changes in libraries.