Optimize PostHog costs through tier selection, sampling, and usage monitoring. Use when analyzing PostHog billing, reducing API costs, or implementing usage monitoring and budget alerts. Trigger with phrases like "posthog cost", "posthog billing", "reduce posthog costs", "posthog pricing", "posthog expensive", "posthog budget".
From posthog-packnpx claudepluginhub nickloveinvesting/nick-love-plugins --plugin posthog-packThis skill is limited to using the following tools:
Guides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
Migrates code, prompts, and API calls from Claude Sonnet 4.0/4.5 or Opus 4.1 to Opus 4.5, updating model strings on Anthropic, AWS, GCP, Azure platforms.
Details PluginEval's skill quality evaluation: 3 layers (static, LLM judge), 10 dimensions, rubrics, formulas, anti-patterns, badges. Use to interpret scores, improve triggering, calibrate thresholds.
Reduce PostHog event-based pricing costs by controlling event volume, optimizing autocapture settings, and leveraging the generous free tier. PostHog charges per event with a free tier of 1M events/month, then ~$0.00031 per event beyond that.
set -euo pipefail
# Check which events consume the most quota
curl "https://app.posthog.com/api/projects/PROJECT_ID/insights/trend/?events=[{\"id\":\"$pageview\"},{\"id\":\"$autocapture\"},{\"id\":\"$screen\"}]&date_from=-30d&interval=week" \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" | \
jq '.result[] | {event: .label, total_30d: (.data | add)}'
// posthog-init.ts - Configure autocapture to skip noisy elements
posthog.init('phc_YOUR_KEY', {
autocapture: {
dom_event_allowlist: ['click', 'submit'], // Skip scroll, change, etc.
element_allowlist: ['a', 'button', 'form', 'input[type=submit]'],
css_selector_allowlist: ['.track-click'], // Only track explicitly marked elements
url_ignorelist: ['/health', '/api/internal'], // Skip internal endpoints
},
// Disable session recording for anonymous users to save on recording quota
session_recording: {
maskAllInputs: true,
},
});
// Reduce non-critical event volume by sampling
posthog.init('phc_YOUR_KEY', {
// Only send 10% of pageview events (still statistically significant)
before_send: (event) => {
if (event.event === '$pageview') {
return Math.random() < 0.1 ? event : null; // 90% reduction
}
// Always send business-critical events
if (['purchase', 'signup', 'upgrade'].includes(event.event)) {
return event;
}
// Sample other events at 50%
return Math.random() < 0.5 ? event : null;
},
});
// Bots generate significant event volume without business value
posthog.init('phc_YOUR_KEY', {
before_send: (event) => {
const ua = navigator.userAgent.toLowerCase();
const isBot = /bot|crawler|spider|scrapy|headless|phantom/i.test(ua);
return isBot ? null : event;
},
});
set -euo pipefail
# Check current event usage vs billing tier
curl "https://app.posthog.com/api/organizations/ORG_ID/billing/" \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" | \
jq '{
events_used: .events_current_usage,
events_limit: .events_plan_limit,
usage_pct: (.events_current_usage / .events_plan_limit * 100),
estimated_cost: (if .events_current_usage > 1000000 then ((.events_current_usage - 1000000) * 0.00031) else 0 end) # 1000000 = 1M limit
}'
| Issue | Cause | Solution |
|---|---|---|
| Event volume spike | Autocapture on high-frequency element | Add element to css_selector_denylist |
| Bill higher than expected | Bot traffic generating events | Add bot filtering in before_send |
| Missing critical events | Sampling too aggressive | Exclude business events from sampling |
| Free tier exceeded early | New feature launched without volume estimate | Forecast events before launch |
Basic usage: Apply posthog cost tuning to a standard project setup with default configuration options.
Advanced scenario: Customize posthog cost tuning for production environments with multiple constraints and team-specific requirements.