$npx -y skills add heymegabyte/claude-skills --skill 13-observability-and-growthFull instrumentation from day one. PostHog consolidates product analytics + feature flags + error tracking (one platform, one bill). GA4 via GTM (14-step automation, custom dimensions over events, server-side tagging). Sentry (deep error tracking + performance). Stripe (webhook-f
| 1 | # 13 — Observability and Growth |
| 2 | |
| 3 | Tiered PostHog+Sentry+GA4 stacks wired from day one; feature flags, PLG patterns, incident auto-remediation. |
| 4 | |
| 5 | ## Instrumentation tiers |
| 6 | |
| 7 | Per `_kernel/standards.md#integrations`: |
| 8 | |
| 9 | - **Tier 1 (solo)** — PostHog + Workers Tracing OTLP (2 vendors max, cookie-free, free tier covers <10k MAU) |
| 10 | - **Tier 2 (enterprise)** — + Sentry @sentry/cloudflare v9 + GA4/GTM + Axiom |
| 11 | - **Tier 3 (LLM-heavy >10k calls/mo)** — + AI Gateway |
| 12 | |
| 13 | ## PostHog (Tier 1 cornerstone) |
| 14 | |
| 15 | - Snippet on every HTML page w/ `persistence:'memory'` (cookie-free); `capture_pageview` + `capture_pageleave` + `autocapture:true` |
| 16 | - Unified platform: product analytics + feature flags + session replay + error tracking |
| 17 | - CSP: `script-src` + `connect-src` for posthog domain |
| 18 | - Per-feature event naming: `<feature>:<action>` (`signup:complete`, `editor:save`, `share:copy`) |
| 19 | |
| 20 | ## Sentry (Tier 2) |
| 21 | |
| 22 | - `@sentry/cloudflare` v9 + `withSentry` wrapper; project via `mcp__sentry__create_project` (org:`megabyte-labs`) |
| 23 | - `SENTRY_DSN` via `wrangler secret put` |
| 24 | - Pattern: `withSentry(env => ({ dsn, tracesSampleRate: 1.0, sendDefaultPii: false }), worker)` |
| 25 | - Breadcrumbs before risky ops; capture exception w/ context tags (`worker` | `route` | `userId`) |
| 26 | - Release tracking via `SENTRY_RELEASE` env; Workers Tracing handles I/O spans |
| 27 | |
| 28 | ## Workers Tracing (Tier 1 + 2) / GA4 + GTM (Tier 2) / AI Gateway (Tier 3) |
| 29 | |
| 30 | - Workers Tracing: `[observability] enabled = true` in `wrangler.jsonc` — zero-config OTel I/O tracing; export to Axiom, Honeycomb, Grafana, Datadog via `@opentelemetry/exporter-trace-otlp-http` |
| 31 | - GA4 + GTM: container snippet (head script + noscript iframe); CSP: `googletagmanager.com` + `google-analytics.com` + `analytics.google.com` + `region1.google-analytics.com`; server-side tagging for EU; custom dimensions over custom events |
| 32 | - AI Gateway: `env.AI.run()` auto-routes; direct Anthropic: `https://gateway.ai.cloudflare.com/v1/{account}/{gateway}/anthropic/v1/messages`; caching + rate-limit + fallback + per-call logging |
| 33 | |
| 34 | ## Stripe (SaaS billing only — per `rules/payments-routing.md`) |
| 35 | |
| 36 | - Webhook-first w/ idempotent processing (D1 dedupe table `payment_events(event_id, source, processed_at)` UNIQUE) |
| 37 | - `Stripe-Signature` HMAC + 5-min replay window |
| 38 | - Mint products + prices via MCP (idempotent via `lookup_key`); subscription state machine in D1 |
| 39 | - `STRIPE_WEBHOOK_SECRET` via `POST /v1/webhook_endpoints` |
| 40 | |
| 41 | ## Square (accept-money default — per `rules/payments-routing.md`) |
| 42 | |
| 43 | - Square Web Payments SDK card form + Apple Pay + Google Pay + Cash App Pay |
| 44 | - `Square-Signature` HMAC-SHA256 w/ 6-hr replay window; `idempotency_key` UUID per request (24-hr dedupe) |
| 45 | - Nonprofit verified-501c3 discount (2.6%+10¢ vs 3.5%+15¢) |
| 46 | |
| 47 | ## Listmonk (newsletter — self-hosted on Coolify) |
| 48 | |
| 49 | - Amazon SES SMTP relay (`LISTMONK_FROM_EMAIL`); `listmonkSendTx(env, { templateAlias, ... })` via KV-cached alias→id map |
| 50 | - Templates in `emails/*.html` synced via `scripts/listmonk-sync.mjs` |
| 51 | - Auth: `Authorization: token <user>:<key>` (Listmonk 3.x API-user pattern) |
| 52 | |
| 53 | ## PLG 7-Layer Framework |
| 54 | |
| 55 | 1. **Discovery** — SEO + AI search + word-of-mouth + paid |
| 56 | 2. **Sign-up** — passwordless preferred (Clerk M2M JWT) |
| 57 | 3. **Activation** — first-value-in-X-min metric (aha moment per `rules/feature-flags.md` instrumentation) |
| 58 | 4. **Engagement** — DAU/MAU ratio, session depth |
| 59 | 5. **Retention** — D1/D7/D30 cohort |
| 60 | 6. **Revenue** — upgrade trigger, expansion |
| 61 | 7. **Referral** — viral coefficient, two-sided rewards |
| 62 | |
| 63 | ## Programmatic SEO (5 page types) |
| 64 | |
| 65 | - `/integrations/{tool}` · `/compare/{a}-vs-{b}` · `/for/{audience}` · `/templates/{type}` · `/{city}-{service}` |
| 66 | - Each: unique H1 + meta desc + 800+ unique words + 1 unique image + 3+ internal links |