posthog
Use this skill when working with PostHog - product analytics, web analytics, feature flags, A/B testing, experiments, session replay, error tracking, surveys, LLM observability, or data warehouse. Triggers on any PostHog-related task including capturing events, identifying users, evaluating feature flags, creating experiments, setting up surveys, tracking errors, and querying analytics data via the PostHog API or SDKs (posthog-js, posthog-node, posthog-python).
analytics analyticsfeature-flagsab-testingsurveyserror-trackingsession-replayWhat is posthog?
Use this skill when working with PostHog - product analytics, web analytics, feature flags, A/B testing, experiments, session replay, error tracking, surveys, LLM observability, or data warehouse. Triggers on any PostHog-related task including capturing events, identifying users, evaluating feature flags, creating experiments, setting up surveys, tracking errors, and querying analytics data via the PostHog API or SDKs (posthog-js, posthog-node, posthog-python).
posthog
posthog is a production-ready AI agent skill for claude-code, gemini-cli, openai-codex, and 1 more. Working with PostHog - product analytics, web analytics, feature flags, A/B testing, experiments, session replay, error tracking, surveys, LLM observability, or data warehouse.
Quick Facts
| Field | Value |
|---|---|
| Category | analytics |
| Version | 0.1.0 |
| Platforms | claude-code, gemini-cli, openai-codex, mcp |
| License | MIT |
How to Install
- Make sure you have Node.js installed on your machine.
- Run the following command in your terminal:
npx skills add AbsolutelySkilled/AbsolutelySkilled --skill posthog- The posthog skill is now available in your AI coding agent (Claude Code, Gemini CLI, OpenAI Codex, etc.).
Overview
PostHog is an open-source product analytics platform that combines product analytics, web analytics, session replay, feature flags, A/B testing, error tracking, surveys, and LLM observability into a single platform. It can be self-hosted or used as a cloud service (US or EU). Agents interact with PostHog primarily through its JavaScript, Node.js, or Python SDKs for client/server-side instrumentation, and through its REST API for querying data and managing resources.
Tags
analytics feature-flags ab-testing surveys error-tracking session-replay
Platforms
- claude-code
- gemini-cli
- openai-codex
- mcp
Related Skills
Pair posthog with these complementary skills:
Frequently Asked Questions
What is posthog?
Use this skill when working with PostHog - product analytics, web analytics, feature flags, A/B testing, experiments, session replay, error tracking, surveys, LLM observability, or data warehouse. Triggers on any PostHog-related task including capturing events, identifying users, evaluating feature flags, creating experiments, setting up surveys, tracking errors, and querying analytics data via the PostHog API or SDKs (posthog-js, posthog-node, posthog-python).
How do I install posthog?
Run npx skills add AbsolutelySkilled/AbsolutelySkilled --skill posthog in your terminal. The skill will be immediately available in your AI coding agent.
What AI agents support posthog?
This skill works with claude-code, gemini-cli, openai-codex, mcp. Install it once and use it across any supported AI coding agent.
Maintainers
Generated from AbsolutelySkilled
SKILL.md
PostHog
PostHog is an open-source product analytics platform that combines product analytics, web analytics, session replay, feature flags, A/B testing, error tracking, surveys, and LLM observability into a single platform. It can be self-hosted or used as a cloud service (US or EU). Agents interact with PostHog primarily through its JavaScript, Node.js, or Python SDKs for client/server-side instrumentation, and through its REST API for querying data and managing resources.
When to use this skill
Trigger this skill when the user:
- Wants to capture custom events or identify users with PostHog
- Needs to set up or evaluate feature flags (boolean, multivariate, or remote config)
- Wants to create or manage A/B tests and experiments
- Asks about session replay setup or configuration
- Needs to create or customize in-app surveys
- Wants to set up error tracking or exception autocapture
- Needs to query analytics data via the PostHog API
- Asks about group analytics, cohorts, or person properties
Do NOT trigger this skill for:
- General analytics strategy that doesn't involve PostHog specifically
- Competing tools like Amplitude, Mixpanel, or LaunchDarkly unless comparing
Setup & authentication
Environment variables
# Required for all SDKs
POSTHOG_API_KEY=phc_your_project_api_key
# Required for server-side private API access
POSTHOG_PERSONAL_API_KEY=phx_your_personal_api_key
# Host (defaults to US cloud)
POSTHOG_HOST=https://us.i.posthog.comPostHog has two API types:
- Public endpoints (
/e,/flags) - use project API key (starts withphc_), no rate limits - Private endpoints (CRUD) - use personal API key (starts with
phx_), rate-limited
Cloud hosts:
- US:
https://us.i.posthog.com(public) /https://us.posthog.com(private) - EU:
https://eu.i.posthog.com(public) /https://eu.posthog.com(private)
Installation
# JavaScript (browser)
npm install posthog-js
# Node.js (server)
npm install posthog-node
# Python
pip install posthogBasic initialization
// Browser - posthog-js
import posthog from 'posthog-js'
posthog.init('phc_your_project_api_key', {
api_host: 'https://us.i.posthog.com',
person_profiles: 'identified_only',
})// Node.js - posthog-node
import { PostHog } from 'posthog-node'
const client = new PostHog('phc_your_project_api_key', {
host: 'https://us.i.posthog.com',
})
// Flush before process exit
await client.shutdown()# Python
from posthog import Posthog
posthog = Posthog('phc_your_project_api_key', host='https://us.i.posthog.com')Core concepts
PostHog's data model centers on events, persons, and properties:
Events are actions users take (page views, clicks, custom events). Each event has a
distinct_id(user identifier), event name, timestamp, and optional properties. PostHog autocaptures pageviews, clicks, and form submissions by default in the JS SDK.Persons are user profiles built from events. Use
posthog.identify()to link anonymous and authenticated sessions. Person properties ($set,$set_once) store user attributes for segmentation and targeting.Groups let you associate events with entities like companies or teams, enabling B2B analytics. Groups require a group type (e.g.,
company) and a group key.Feature flags control feature rollout with boolean, multivariate, or remote config types. Flags evaluate against release conditions (user properties, cohorts, percentages). Local evaluation on the server avoids network round-trips.
Insights are analytics queries: Trends, Funnels, Retention, Paths, Lifecycle, and Stickiness. They power dashboards for product analytics and web analytics.
Common tasks
Capture a custom event
// Browser
posthog.capture('purchase_completed', {
item_id: 'sku_123',
amount: 49.99,
currency: 'USD',
})
// Node.js
client.capture({
distinctId: 'user_123',
event: 'purchase_completed',
properties: { item_id: 'sku_123', amount: 49.99 },
})# Python
posthog.capture('user_123', 'purchase_completed', {
'item_id': 'sku_123',
'amount': 49.99,
})Identify a user and set properties
// Browser - link anonymous ID to authenticated user
posthog.identify('user_123', {
email: 'user@example.com',
plan: 'pro',
})
// Set properties later without an event
posthog.people.set({ company: 'Acme Corp' })# Python
posthog.identify('user_123', {
'$set': {'email': 'user@example.com', 'plan': 'pro'},
'$set_once': {'first_seen': '2026-03-14'},
})Evaluate a feature flag
// Browser - async check
posthog.onFeatureFlags(() => {
if (posthog.isFeatureEnabled('new-checkout')) {
showNewCheckout()
}
})
// Get multivariate value
const variant = posthog.getFeatureFlag('checkout-experiment')// Node.js - with local evaluation (requires personal API key)
const client = new PostHog('phc_key', {
host: 'https://us.i.posthog.com',
personalApiKey: 'phx_your_personal_api_key',
})
const enabled = await client.isFeatureEnabled('new-checkout', 'user_123')
const variant = await client.getFeatureFlag('checkout-experiment', 'user_123')# Python - with local evaluation
posthog = Posthog('phc_key', host='https://us.i.posthog.com',
personal_api_key='phx_your_personal_api_key')
enabled = posthog.get_feature_flag('new-checkout', 'user_123')Feature flag local evaluation polls every 5 minutes by default. Configure with
featureFlagsPollingInterval(Node) orpoll_interval(Python).
Get feature flag payload
// Browser
const payload = posthog.getFeatureFlagPayload('my-flag')
// Node.js
const payload = await client.getFeatureFlagPayload('my-flag', 'user_123')Capture events with group analytics
// Browser - associate event with a company group
posthog.group('company', 'company_id_123', {
name: 'Acme Corp',
plan: 'enterprise',
})
posthog.capture('feature_used', { feature: 'dashboard' })# Python
posthog.capture('user_123', 'feature_used',
properties={'feature': 'dashboard'},
groups={'company': 'company_id_123'})
posthog.group_identify('company', 'company_id_123', {
'name': 'Acme Corp',
'plan': 'enterprise',
})Query data via the private API
# List events for a person
curl -H "Authorization: Bearer phx_your_personal_api_key" \
"https://us.posthog.com/api/projects/:project_id/events/?person_id=user_123"
# Get feature flag details
curl -H "Authorization: Bearer phx_your_personal_api_key" \
"https://us.posthog.com/api/projects/:project_id/feature_flags/"
# Create an annotation
curl -X POST -H "Authorization: Bearer phx_your_personal_api_key" \
-H "Content-Type: application/json" \
-d '{"content": "Deployed v2.0", "date_marker": "2026-03-14T00:00:00Z"}' \
"https://us.posthog.com/api/projects/:project_id/annotations/"Private API rate limits: 240/min for analytics, 480/min for CRUD, 2400/hr for queries. Limits are organization-wide across all keys.
Set up error tracking (Python)
from posthog import Posthog
posthog = Posthog('phc_key',
host='https://us.i.posthog.com',
enable_exception_autocapture=True)
# Manual exception capture
try:
risky_operation()
except Exception as e:
posthog.capture_exception(e)Serverless environment setup
// Node.js Lambda - flush immediately
const client = new PostHog('phc_key', {
host: 'https://us.i.posthog.com',
flushAt: 1,
flushInterval: 0,
})
export async function handler(event) {
client.capture({ distinctId: 'user', event: 'lambda_invoked' })
await client.shutdown()
return { statusCode: 200 }
}Error handling
| Error | Cause | Resolution |
|---|---|---|
401 Unauthorized |
Invalid project API key or personal API key | Verify key in PostHog project settings. Public endpoints use phc_ keys, private use phx_ keys |
400 Bad Request |
Malformed payload or invalid project ID | Check event structure matches expected schema. Verify project ID in URL |
429 Rate Limited |
Exceeded private API rate limits | Back off and retry. Rate limits: 240/min analytics, 480/min CRUD. Only private endpoints are limited |
Feature flag returns undefined |
Flag not loaded yet or key mismatch | Use onFeatureFlags() callback in browser. Verify flag key matches exactly |
| Events not appearing | Batch not flushed (serverless) | Call shutdown() or flush() before process exits. Use flushAt: 1 in serverless |
Gotchas
Serverless functions silently drop events if
shutdown()is not awaited - The Node.js PostHog client batches events and flushes them asynchronously. In Lambda or Edge functions, the process exits before the batch is sent unless you callawait client.shutdown()at the end of every handler. SettingflushAt: 1andflushInterval: 0ensures immediate dispatch but adds network latency to each handler invocation.Feature flag local evaluation requires the personal API key, not the project key -
isFeatureEnabled()on the server will make a network call to PostHog on every invocation unless local evaluation is configured. Local evaluation requirespersonalApiKey(starts withphx_), not the project API key (phc_). Using the wrong key silently falls back to per-call evaluation with no error.posthog.identify()in the browser does not immediately affect feature flag evaluation - After callingidentify(), the SDK asynchronously reloads flags for the new identity. Code that immediately callsisFeatureEnabled()afteridentify()will receive the flags for the old anonymous identity. Use theonFeatureFlags()callback orawait posthog.reloadFeatureFlags()to ensure flags reflect the new identity.person_profiles: 'identified_only'prevents anonymous user tracking - Settingperson_profilestoidentified_onlymeans events from anonymous (non-identified) users are captured but no person profile is created, and those events cannot be used in funnels or cohorts that require a person. If you need funnel analysis including pre-signup behavior, use'always'or ensure you identify users early in the funnel.Private API rate limits are per-organization, not per-key - All personal API keys within an organization share the same rate limit pool (240/min for analytics queries). Multiple automated scripts or CI jobs querying the private API simultaneously can exhaust the organization-wide limit and affect interactive usage in the PostHog UI.
References
For detailed content on specific sub-domains, read the relevant file from the
references/ folder:
references/feature-flags.md- advanced flag patterns, local evaluation, bootstrapping, experimentsreferences/api.md- full REST API endpoint reference, pagination, rate limitsreferences/surveys-and-more.md- surveys, session replay, web analytics, LLM observability
Only load a references file if the current task requires it - they are long and will consume context.
References
api.md
PostHog REST API Reference
Authentication
Two authentication methods:
| Type | Key prefix | Used for | Rate limited |
|---|---|---|---|
| Project API key | phc_ |
Public endpoints (event capture, flag eval) | No |
| Personal API key | phx_ |
Private endpoints (CRUD, queries) | Yes |
Public endpoints accept the project API key in the request body:
{ "api_key": "phc_your_key", "distinct_id": "user_123" }Private endpoints use Bearer auth:
Authorization: Bearer phx_your_personal_api_keyBase URLs
| Deployment | Public (capture/flags) | Private (API) |
|---|---|---|
| US Cloud | https://us.i.posthog.com |
https://us.posthog.com |
| EU Cloud | https://eu.i.posthog.com |
https://eu.posthog.com |
| Self-hosted | Your instance domain | Your instance domain |
Rate limits (private endpoints)
| Endpoint type | Limit |
|---|---|
| Analytics endpoints | 240/minute, 1200/hour |
| Query endpoint | 2400/hour |
| Feature flag local evaluation | 600/minute |
| CRUD operations | 480/minute, 4800/hour |
Limits apply organization-wide across all users and API keys.
Pagination
All list endpoints return paginated results:
{
"count": 150,
"next": "https://us.posthog.com/api/projects/1/events/?limit=100&offset=100",
"previous": null,
"results": [...]
}Default page size: 100 items. Follow next URL to get subsequent pages.
Key public endpoints
Capture events - POST /i/v0/e
curl -X POST "https://us.i.posthog.com/i/v0/e" \
-H "Content-Type: application/json" \
-d '{
"api_key": "phc_key",
"event": "purchase",
"distinct_id": "user_123",
"properties": {
"amount": 49.99,
"$current_url": "https://example.com/checkout"
},
"timestamp": "2026-03-14T10:00:00Z"
}'Batch capture - POST /batch
curl -X POST "https://us.i.posthog.com/batch" \
-H "Content-Type: application/json" \
-d '{
"api_key": "phc_key",
"batch": [
{"event": "pageview", "distinct_id": "user_1", "timestamp": "2026-03-14T10:00:00Z"},
{"event": "click", "distinct_id": "user_2", "timestamp": "2026-03-14T10:00:01Z"}
]
}'Evaluate feature flags - POST /decide?v=3
curl -X POST "https://us.i.posthog.com/decide?v=3" \
-H "Content-Type: application/json" \
-d '{
"api_key": "phc_key",
"distinct_id": "user_123",
"person_properties": {"plan": "pro"}
}'Returns:
{
"featureFlags": {"new-checkout": true, "experiment": "variant-a"},
"featureFlagPayloads": {"app-config": "{\"theme\":\"dark\"}"}
}Key private endpoints
All private endpoints follow the pattern:
https://us.posthog.com/api/projects/:project_id/<resource>/Events
# List events
GET /api/projects/:id/events/
GET /api/projects/:id/events/?event=purchase&person_id=user_123
# Get single event
GET /api/projects/:id/events/:event_id/Persons
# List persons
GET /api/projects/:id/persons/
# Search persons
GET /api/projects/:id/persons/?search=user@example.com
# Get person by distinct ID
GET /api/projects/:id/persons/?distinct_id=user_123
# Delete a person
DELETE /api/projects/:id/persons/:person_id/Feature flags
# List flags
GET /api/projects/:id/feature_flags/
# Create a flag
POST /api/projects/:id/feature_flags/
{
"key": "new-checkout",
"name": "New checkout flow",
"active": true,
"filters": {
"groups": [{"properties": [], "rollout_percentage": 50}]
}
}
# Update a flag
PATCH /api/projects/:id/feature_flags/:flag_id/
# Delete a flag
DELETE /api/projects/:id/feature_flags/:flag_id/Experiments
# List experiments
GET /api/projects/:id/experiments/
# Create an experiment
POST /api/projects/:id/experiments/
{
"name": "Signup flow test",
"feature_flag_key": "signup-experiment",
"filters": {...}
}Dashboards
# List dashboards
GET /api/projects/:id/dashboards/
# Create a dashboard
POST /api/projects/:id/dashboards/
{ "name": "Product metrics", "description": "Key KPIs" }Insights (saved queries)
# List insights
GET /api/projects/:id/insights/
# Create a trend insight
POST /api/projects/:id/insights/
{
"name": "Daily active users",
"filters": {
"insight": "TRENDS",
"events": [{"id": "$pageview", "math": "dau"}],
"date_from": "-30d"
}
}Cohorts
# List cohorts
GET /api/projects/:id/cohorts/
# Create a cohort
POST /api/projects/:id/cohorts/
{
"name": "Power users",
"groups": [{"properties": [{"key": "plan", "value": "pro", "type": "person"}]}]
}Annotations
# Create an annotation (e.g. deployment marker)
POST /api/projects/:id/annotations/
{
"content": "Deployed v2.0",
"date_marker": "2026-03-14T00:00:00Z",
"scope": "project"
}Response codes
| Code | Meaning |
|---|---|
200 |
Success (for capture: payload received, not guaranteed ingested) |
400 |
Bad request - invalid payload or project ID |
401 |
Unauthorized - invalid API key |
404 |
Resource not found |
429 |
Rate limited - back off and retry |
503 |
Database unavailable (self-hosted only) |
Query API (HogQL)
PostHog supports HogQL for custom queries:
POST /api/projects/:id/query/
{
"query": {
"kind": "HogQLQuery",
"query": "SELECT count() FROM events WHERE event = 'purchase' AND timestamp > now() - interval 7 day"
}
}HogQL is a SQL-like language that queries PostHog's ClickHouse backend. It supports standard SQL functions plus PostHog-specific functions for working with properties.
feature-flags.md
PostHog Feature Flags & Experiments
Feature flag types
Boolean (release toggle)
Returns true when enabled and conditions match, false when disabled, or
undefined/null when conditions don't match.
if (posthog.isFeatureEnabled('new-checkout')) {
renderNewCheckout()
}Multivariate
Returns a variant key string (e.g. control, test, variant-a). Each variant
has a configurable rollout percentage that must total 100%.
const variant = posthog.getFeatureFlag('checkout-experiment')
if (variant === 'test') {
renderTestCheckout()
} else {
renderControlCheckout()
}Remote config
Delivers a static configuration value consistently to all matching users. Does not support percentage-based rollouts. Used for dynamic configuration without deploys.
const config = posthog.getFeatureFlagPayload('app-config')
// Returns the JSON payload attached to the flagRelease conditions
Conditions evaluate top-to-bottom, first match wins. Options:
- Match by user (default) - target individual persons by properties
- Match by device - target by device properties
- Match by group - target by group properties (requires group analytics)
Filters available:
- Person properties (exact, contains, regex, is set/not set)
- Cohort membership
- Geographic location (country, city)
- Semantic version comparisons (for app version targeting)
- Percentage rollout (0-100%)
Local evaluation (server-side)
Local evaluation avoids a network call per flag check by polling flag definitions and evaluating them locally. Requires a personal API key.
// Node.js
const client = new PostHog('phc_key', {
host: 'https://us.i.posthog.com',
personalApiKey: 'phx_personal_key',
featureFlagsPollingInterval: 30000, // poll every 30s (default: 300000ms / 5min)
})
// This evaluates locally - no network call
const flag = await client.getFeatureFlag('my-flag', 'user_123', {
personProperties: { plan: 'pro', country: 'US' },
groupProperties: { company: { name: 'Acme' } },
})# Python
posthog = Posthog('phc_key',
host='https://us.i.posthog.com',
personal_api_key='phx_personal_key',
poll_interval=30) # seconds
flag = posthog.get_feature_flag('my-flag', 'user_123',
person_properties={'plan': 'pro'},
group_properties={'company': {'name': 'Acme'}})Important: When using local evaluation, you must provide personProperties
and groupProperties that match the conditions. If a flag condition uses a
property you didn't provide, it falls back to a remote API call.
Rate limit for local evaluation polling: 600 requests/minute.
Bootstrapping (client-side)
Bootstrap flags on page load to avoid flickering. Pass flag values from server-side rendering.
posthog.init('phc_key', {
api_host: 'https://us.i.posthog.com',
bootstrap: {
distinctID: 'user_123',
featureFlags: {
'new-checkout': true,
'checkout-experiment': 'test',
},
featureFlagPayloads: {
'app-config': { theme: 'dark' },
},
},
})The
distinctIDin bootstrap must match the user's actual distinct ID. If it doesn't, flags will be re-fetched from the server, causing a flash.
Experiments / A/B testing
Experiments are built on top of feature flags with statistical analysis.
Creating an experiment
- Create a multivariate feature flag with
controlandtestvariants - Create an experiment linked to that flag
- Define a goal metric (trend, funnel, or secondary metrics)
- Set minimum sample size and run duration
- Launch the experiment (activates the linked flag)
Evaluating in code
Experiments use the same flag evaluation methods:
const variant = posthog.getFeatureFlag('signup-experiment')
if (variant === 'test') {
renderNewSignupFlow()
}
// PostHog automatically tracks exposure via $feature_flag_called eventStatistical significance
PostHog uses a Bayesian approach to calculate statistical significance. Results show win probability and credible intervals. The experiment dashboard indicates when significance is reached.
Feature flag best practices
- Use descriptive keys -
new-checkout-flownotflag-1 - Clean up stale flags - remove flags after full rollout to reduce evaluation overhead
- Use local evaluation server-side - avoids latency and API dependency for critical paths
- Bootstrap client-side - prevents UI flickering on page load
- Provide person properties for local eval - missing properties trigger remote fallback
- Use payloads for configuration - attach JSON payloads to flags instead of hardcoding values
Feature Flags API
# List all flags
curl -H "Authorization: Bearer phx_key" \
"https://us.posthog.com/api/projects/:project_id/feature_flags/"
# Get a specific flag
curl -H "Authorization: Bearer phx_key" \
"https://us.posthog.com/api/projects/:project_id/feature_flags/:id/"
# Evaluate flags for a user (public endpoint)
curl -X POST "https://us.i.posthog.com/decide?v=3" \
-H "Content-Type: application/json" \
-d '{"api_key": "phc_key", "distinct_id": "user_123"}'The /decide endpoint returns all active flags and their values for a given user.
This is what the SDKs call internally.
surveys-and-more.md
PostHog Surveys, Session Replay, Web Analytics & More
Surveys
Survey types
- Popover - prebuilt UI in the bottom corner of the screen
- API - custom UI, PostHog handles targeting logic and analytics
- Feedback button - persistent tab for collecting feedback
- Hosted - external URL or iframe-embedded, anonymous by default
Question types
- Freeform text
- Link/notification (display-only)
- Rating - emoji scale
- Rating - number scale
- Single choice select
- Multiple choice select
Display conditions
- Feature flag targeting
- URL matching
- Device type filtering
- CSS selector matching
- Wait periods between viewings
- Person/group property targeting
- Event-based triggers
Creating surveys via API
POST /api/projects/:id/surveys/
{
"name": "NPS Survey",
"type": "popover",
"questions": [
{
"type": "rating",
"question": "How likely are you to recommend us?",
"scale": 10,
"lowerBoundLabel": "Not likely",
"upperBoundLabel": "Very likely"
}
],
"conditions": {
"url": "https://example.com/dashboard"
},
"start_date": "2026-03-14T00:00:00Z"
}Handling surveys in code (API mode)
// Get active surveys for the current user
posthog.getActiveMatchingSurveys((surveys) => {
surveys.forEach(survey => {
// Render custom survey UI
renderSurvey(survey)
})
})
// Send survey response
posthog.capture('survey sent', {
$survey_id: 'survey_uuid',
$survey_response: 'Great product!',
$survey_response_1: 9, // for multi-question surveys
})Repeating surveys
Surveys can repeat via event triggers, scheduled intervals, or when display conditions are met again. Partial responses are tracked by default with a unique submission ID per attempt.
Session replay
Session replay records user sessions as replayable videos. It captures DOM changes, mouse movements, clicks, console logs, and network requests.
Setup (browser)
Session replay is enabled by default with posthog-js. Configure it during init:
posthog.init('phc_key', {
api_host: 'https://us.i.posthog.com',
session_recording: {
maskAllInputs: true, // mask input values
maskTextContent: false, // mask text content
recordCrossOriginIframes: false,
},
})Conditional recording
Record only specific sessions to reduce volume:
posthog.init('phc_key', {
api_host: 'https://us.i.posthog.com',
disable_session_recording: true, // disable by default
})
// Start recording programmatically
posthog.startSessionRecording()Replay triggers
PostHog can automatically start recording when specific events are queued, capturing a buffer of activity before the trigger event.
Privacy controls
maskAllInputs: true- replaces input values with asterisksmaskTextContent: true- masks all text content- Add
ph-no-captureclass to any element to exclude it from recording - Add
ph-maskclass to mask specific elements
Web analytics
PostHog web analytics provides a Google Analytics-like dashboard with:
- Pageviews, unique visitors, sessions
- Bounce rate, session duration
- Traffic sources, UTM parameters
- Device, browser, OS, and location breakdowns
- Entry/exit pages
Web analytics uses autocaptured $pageview events and requires no additional
setup beyond the standard JS SDK installation. The dashboard is available at
/web in your PostHog instance.
Key autocaptured events
$pageview- page loads$pageleave- page exits (captures time on page)$autocapture- clicks, form submissions, input changes$rageclick- repeated rapid clicks (frustration signal)
UTM tracking
PostHog automatically captures UTM parameters from URLs:
utm_source,utm_medium,utm_campaign,utm_term,utm_content- Stored as properties on the
$pageviewevent
Error tracking
PostHog captures JavaScript errors and unhandled exceptions automatically.
Browser setup
Error tracking is enabled by default in posthog-js. It captures:
- Unhandled exceptions
- Unhandled promise rejections
- Console errors (optional)
Python setup
posthog = Posthog('phc_key',
host='https://us.i.posthog.com',
enable_exception_autocapture=True)
# Manual capture
try:
risky_operation()
except Exception as e:
posthog.capture_exception(e)Node.js setup
// Errors are captured via the SDK's error tracking module
// Manual capture
client.captureException(error, 'user_123')LLM observability
PostHog provides observability for LLM-powered applications via the @posthog/ai
package (Node.js) or built-in Python SDK support.
What it tracks
- LLM API calls (model, tokens, latency, cost)
- Prompt/completion content (optional, can be masked)
- Error rates and failure modes
- Token usage over time
Node.js setup
import { PostHogAI } from '@posthog/ai'
import OpenAI from 'openai'
const openai = new PostHogAI(new OpenAI(), posthogClient)
// Use openai as normal - PostHog wraps and tracks all callsPython setup
LLM analytics are built into the Python SDK with context managers and decorators for tracking LLM calls.
Data warehouse
PostHog includes a built-in data warehouse that can:
- Import data from external sources (Stripe, Hubspot, Postgres, S3, etc.)
- Join external data with PostHog events and persons
- Query everything with HogQL
External data sources
POST /api/projects/:id/external_data_sources/
{
"source_type": "Stripe",
"job_inputs": {
"stripe_secret_key": "sk_..."
}
}This syncs Stripe data (charges, customers, invoices) into PostHog's warehouse for cross-referencing with product analytics.
Frequently Asked Questions
What is posthog?
Use this skill when working with PostHog - product analytics, web analytics, feature flags, A/B testing, experiments, session replay, error tracking, surveys, LLM observability, or data warehouse. Triggers on any PostHog-related task including capturing events, identifying users, evaluating feature flags, creating experiments, setting up surveys, tracking errors, and querying analytics data via the PostHog API or SDKs (posthog-js, posthog-node, posthog-python).
How do I install posthog?
Run npx skills add AbsolutelySkilled/AbsolutelySkilled --skill posthog in your terminal. The skill will be immediately available in your AI coding agent.
What AI agents support posthog?
posthog works with claude-code, gemini-cli, openai-codex, mcp. Install it once and use it across any supported AI coding agent.