AGENT SKILL

posthog-cost-tuning

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".

License 许可
MIT
最近更新
2026-05-26
Stars
★ 0
Forks
0

01 前言 Front Matter

name
posthog-cost-tuning
author
Jeremy Longshore <jeremy@intentsolutions.io>
license
MIT
version
1.0.0
description
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".
allowed-tools
Read, Grep
compatible-with
claude-code, codex, openclaw

03 SKILL.md 正文

PostHog Cost Tuning

Overview

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.

Prerequisites

  • PostHog Cloud account with billing dashboard access
  • Application instrumented with PostHog SDK
  • Understanding of which events drive business value

Instructions

Step 1: Audit Event Volume by Type

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)}'

Step 2: Disable Unnecessary Autocapture

// 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,
  },
});

Step 3: Sample High-Volume Events

// 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;
  },
});

Step 4: Filter Bot Traffic

// 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;
  },
});

Step 5: Monitor Monthly Costs

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
  }'

Error Handling

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

Examples

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.

Output

  • Configuration files or code changes applied to the project
  • Validation report confirming correct implementation
  • Summary of changes made and their rationale

Resources

  • Official monitoring documentation
  • Community best practices and patterns
  • Related skills in this plugin pack

04 同仓库更多 Skills

SamuelChien
SamuelChien/mega-skills-collection

zustand-store-ts

Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zustand-store-creator

Zustand Store Creator - Auto-activating skill for Frontend Development. Triggers on: zustand store creator, zustand store creator Part of the Frontend Development skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zero-trust-config-helper

Zero Trust Config Helper - Auto-activating skill for Security Advanced. Triggers on: zero trust config helper, zero trust config helper Part of the Security Advanced skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zapier-integration-helper

Zapier Integration Helper - Auto-activating skill for Business Automation. Triggers on: zapier integration helper, zapier integration helper Part of the Business Automation skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zai-cli

Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP. Use when user needs image/video analysis, OCR, UI-to-code conversion, error diagnosis, real-time web search, web page to markdown extraction, or GitHub code exploration. Trigger with phrases like "analyze this image", "search the web for", "read this page", "explore this repo", or "use zai". Requires Z_AI_API_KEY.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

yt-research

Research competitor YouTube channels, niches, and trending topics for your content strategy. Use this skill whenever the user says "research channels", "analyze competitors", "find trending topics", "niche analysis", "competitive research", "what are other creators doing", "scrape YouTube channels", or wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.

★ 0