fix-posthog

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/fix-posthog

/fix-posthog

Run
/check-posthog
, then fix the highest priority issue.
执行
/check-posthog
,然后修复优先级最高的问题。

What This Does

功能说明

  1. Run
    /check-posthog
    to identify issues
  2. Pick the highest priority unfixed issue
  3. Implement the fix
  4. Verify the fix works
  5. Report what was fixed
Fixes one issue per invocation. Run multiple times to fix multiple issues.
  1. 执行
    /check-posthog
    以识别问题
  2. 选择优先级最高的未修复问题
  3. 实施修复方案
  4. 验证修复效果
  5. 报告修复内容
每次调用仅修复一个问题。多次调用可修复多个问题。

Fix Playbook

修复手册

P0: SDK Not Initialized

P0: SDK未初始化

Problem:
initPostHog()
not called or PostHogProvider missing.
Fix:
bash
codex exec --full-auto "Add PostHog initialization. \
Create lib/analytics/posthog.ts with initPostHog(). \
Create PostHogProvider component. \
Add to app/layout.tsx. \
Reference: ~/.claude/skills/posthog/references/sdk-patterns.md. \
Verify: pnpm typecheck" \
--output-last-message /tmp/codex-fix.md 2>/dev/null
问题: 未调用
initPostHog()
或缺少PostHogProvider。
修复方案:
bash
codex exec --full-auto "Add PostHog initialization. \
Create lib/analytics/posthog.ts with initPostHog(). \
Create PostHogProvider component. \
Add to app/layout.tsx. \
Reference: ~/.claude/skills/posthog/references/sdk-patterns.md. \
Verify: pnpm typecheck" \
--output-last-message /tmp/codex-fix.md 2>/dev/null

P0: API Key Missing

P0: API密钥缺失

Problem:
NEXT_PUBLIC_POSTHOG_KEY
not set.
Fix:
bash
undefined
问题: 未设置
NEXT_PUBLIC_POSTHOG_KEY
修复方案:
bash
undefined

Get key from PostHog dashboard

Get key from PostHog dashboard

Add to .env.local

Add to .env.local

echo "NEXT_PUBLIC_POSTHOG_KEY=phc_xxx" >> .env.local
echo "NEXT_PUBLIC_POSTHOG_KEY=phc_xxx" >> .env.local

Add to Vercel production

Add to Vercel production

printf '%s' 'phc_xxx' | vercel env add NEXT_PUBLIC_POSTHOG_KEY production
undefined
printf '%s' 'phc_xxx' | vercel env add NEXT_PUBLIC_POSTHOG_KEY production
undefined

P1: No Reverse Proxy

P1: 无反向代理

Problem: Direct PostHog host gets blocked by ad blockers.
Fix:
bash
codex exec --full-auto "Add PostHog reverse proxy to next.config. \
Add rewrites for /ingest/* to us.i.posthog.com/*. \
Add rewrites for /ingest/static/* to us-assets.i.posthog.com/static/*. \
Update posthog.init to use api_host: '/ingest'. \
Reference: ~/.claude/skills/posthog/references/sdk-patterns.md section 4. \
Verify: pnpm build" \
--output-last-message /tmp/codex-fix.md 2>/dev/null
问题: 直接连接PostHog主机被广告拦截器阻止。
修复方案:
bash
codex exec --full-auto "Add PostHog reverse proxy to next.config. \
Add rewrites for /ingest/* to us.i.posthog.com/*. \
Add rewrites for /ingest/static/* to us-assets.i.posthog.com/static/*. \
Update posthog.init to use api_host: '/ingest'. \
Reference: ~/.claude/skills/posthog/references/sdk-patterns.md section 4. \
Verify: pnpm build" \
--output-last-message /tmp/codex-fix.md 2>/dev/null

P1: Privacy Masking Missing

P1: 隐私屏蔽缺失

Problem:
mask_all_text
and
maskAllInputs
not configured.
Fix:
bash
codex exec --full-auto "Add privacy settings to PostHog init. \
Add mask_all_text: true. \
Add session_recording.maskAllInputs: true. \
Add person_profiles: 'identified_only'. \
Reference: ~/.claude/skills/posthog/references/privacy-checklist.md. \
Verify: pnpm typecheck" \
--output-last-message /tmp/codex-fix.md 2>/dev/null
问题: 未配置
mask_all_text
maskAllInputs
修复方案:
bash
codex exec --full-auto "Add privacy settings to PostHog init. \
Add mask_all_text: true. \
Add session_recording.maskAllInputs: true. \
Add person_profiles: 'identified_only'. \
Reference: ~/.claude/skills/posthog/references/privacy-checklist.md. \
Verify: pnpm typecheck" \
--output-last-message /tmp/codex-fix.md 2>/dev/null

P1: PII in identify() Calls

P1: identify()调用中包含PII数据

Problem: Email/name passed to
posthog.identify()
.
Fix:
bash
codex exec --full-auto "Remove PII from posthog.identify calls. \
Only pass user ID, no email/name/phone properties. \
Search: grep -rE 'posthog.identify.*email|identify.*name' --include='*.ts' --include='*.tsx'. \
Verify: pnpm typecheck && grep -rE 'posthog.identify.*email' returns no results" \
--output-last-message /tmp/codex-fix.md 2>/dev/null
问题:
posthog.identify()
传递了邮箱/姓名。
修复方案:
bash
codex exec --full-auto "Remove PII from posthog.identify calls. \
Only pass user ID, no email/name/phone properties. \
Search: grep -rE 'posthog.identify.*email|identify.*name' --include='*.ts' --include='*.tsx'. \
Verify: pnpm typecheck && grep -rE 'posthog.identify.*email' returns no results" \
--output-last-message /tmp/codex-fix.md 2>/dev/null

P2: No Standard Events

P2: 无标准事件

Problem: No typed event schema defined.
Fix:
bash
codex exec --full-auto "Add typed event schema to PostHog analytics. \
Create StandardEvent type with: user_signed_up, user_activated, subscription_started, subscription_cancelled, feature_used. \
Add trackEvent function that enforces type. \
Reference: ~/.claude/skills/posthog/references/sdk-patterns.md section 1. \
Verify: pnpm typecheck" \
--output-last-message /tmp/codex-fix.md 2>/dev/null
问题: 未定义类型化事件 schema。
修复方案:
bash
codex exec --full-auto "Add typed event schema to PostHog analytics. \
Create StandardEvent type with: user_signed_up, user_activated, subscription_started, subscription_cancelled, feature_used. \
Add trackEvent function that enforces type. \
Reference: ~/.claude/skills/posthog/references/sdk-patterns.md section 1. \
Verify: pnpm typecheck" \
--output-last-message /tmp/codex-fix.md 2>/dev/null

Verification

验证

After each fix, verify with MCP:
undefined
每次修复后,使用MCP进行验证:
undefined

Check events are flowing

Check events are flowing

mcp__posthog__query-run with TrendsQuery for last 1h
mcp__posthog__query-run with TrendsQuery for last 1h

Check for errors

Check for errors

mcp__posthog__list-errors

Manual browser verification:
1. Open DevTools → Network
2. Filter for `ingest` or `posthog`
3. Trigger action → verify request succeeds
4. Check PostHog Live Events → verify event appears
mcp__posthog__list-errors

手动浏览器验证:
1. 打开开发者工具 → 网络
2. 过滤`ingest`或`posthog`
3. 触发操作 → 验证请求成功
4. 查看PostHog实时事件 → 验证事件已显示

Output

输出

After fixing, report:
  • What was fixed
  • How it was verified
  • What's the next priority issue (if any)
修复完成后,报告以下内容:
  • 修复的问题
  • 验证方式
  • 下一个优先级问题(如果有)

Related

相关命令

  • /check-posthog
    - Audit only (no fixes)
  • /log-posthog-issues
    - Create GitHub issues
  • /posthog
    - Full lifecycle workflow
  • /check-posthog
    - 仅审计(不修复)
  • /log-posthog-issues
    - 创建GitHub问题
  • /posthog
    - 完整生命周期工作流