Skip to content

heymegabyte/agent-skills / 13-observability-and-growth

observability-and-growth

Verified

Full 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-first with idempotent processing). Listmonk on Coolify (newsletters via Amazon SES SMTP relay). PLG 7-layer framework. Programmatic SEO (5 page types). Incident auto-remediation via Sentry→Inngest pipeline. AI search (GEO) awareness. Local business conversions (phone_click, direction_click, form_submit, booking_click) with CRO patterns for both SaaS and local.

FileKindSize
SKILL.mdskill md6.8 KB
activation-funnel.mdmarkdown11.0 KB
analytics-configuration.mdmarkdown7.2 KB
conversion-optimization.mdmarkdown4.9 KB
email-marketing-and-listmonk.mdmarkdown8.1 KB
feature-flags-and-experiments.mdmarkdown6.6 KB
mcp-server-registry.mdmarkdown15.0 KB
sentry-alert-rules.mdmarkdown8.7 KB
square-payments.mdmarkdown13.3 KB
stripe-billing.mdmarkdown9.8 KB
user-feedback-collection.mdmarkdown8.9 KB
workers-tracing-otlp.mdmarkdown3.0 KB

analytics-configuration.md

View on GitHub
---
name: "Analytics Configuration"
description: "Canonical owner of GA4 setup (14-step automation), GTM container configuration, PostHog SDK integration, feature flags, A/B tests, event taxonomy, funnel definitions, session recording config, and scroll/engagement tracking. The intelligence layer that powers data-driven decisions."
updated: "2026-04-23"
always-load: false
---

# Analytics Configuration

## Stack

- **Tag Management** — GTM (Google)
- **Web Analytics** — GA4 (Google)
- **Product Analytics** — PostHog Cloud (`us.i.posthog.com`)
- **Feature Flags** — PostHog Cloud
- **A/B Testing** — PostHog Experiments (Cloud)
- **Session Recording** — PostHog Cloud with masked inputs
- **Error Tracking** — Sentry (***AUTO-PROVISION***, sentry.megabyte.space)

## Event Naming

`object_action` (snake_case, past tense): `page_viewed`, `cta_clicked`, `form_submitted`, `signup_completed`, `subscription_started`, `error_displayed`.

## Standard Events

- **`page_viewed`** — props: `path, title, referrer`; trigger: every page
- **`scroll_depth_reached`** — props: `percent (25/50/75/100)`; trigger: scroll milestones
- **`cta_clicked`** — props: `cta_text, cta_location, destination`; trigger: CTA click
- **`form_submitted`** — props: `form_name, success, error_type`; trigger: form submit
- **`signup_completed`** — props: `method, plan`; trigger: account created
- **`purchase_completed`** — props: `amount, currency, plan`; trigger: checkout success
- **`feature_activated`** — props: `feature_name, context`; trigger: first use
- **`search_performed`** — props: `query, results_count`; trigger: site search
- **`error_displayed`** — props: `error_type, page, message`; trigger: error shown

## Rules

1. GTM is ONLY script loader (except Sentry early init)
2. Never hardcode GA4/PostHog in HTML — load via GTM
3. PostHog Cloud with `persistence:'memory'` (cookie-free → no GDPR banner; the cookie-free win is memory-persistence, NOT self-hosting)
4. Every action: GA4 event + PostHog event + Sentry breadcrumb
5. Feature flags BEFORE building feature. Ship behind flag. Remove after 100% rollout.
6. A/B tests require hypothesis + min sample size + defined success metric
7. Session recording masks all inputs by default. PII never recorded.
8. DataLayer pushes happen before action completes (optimistic)
9. No double-counting events across tools
10. Scroll depth: 25/50/75/100% milestones only

## GTM Snippet

```html
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- noscript iframe after <body> -->
```

## PostHog Init

```typescript
posthog.init('phc_PROJECT_KEY', {
  api_host: 'https://us.i.posthog.com',
  capture_pageview: true, capture_pageleave: true, autocapture: true,
  session_recording: { maskAllInputs: true, maskTextSelector: '.sensitive' },
  persistence: 'memory', // No cookies
  loaded: (ph) => { if (import.meta.env.DEV) ph.opt_out_capturing(); },
});
```

## Feature Flags

```typescript
function isFeatureEnabled(flag: string, defaultValue = false): boolean {
  return posthog?.isFeatureEnabled(flag) ?? defaultValue;
}
// With payload: posthog.getFeatureFlagPayload('hero-experiment')
```

## A/B Testing

Define: `name`, `hypothesis`, `variants`, `successMetric`, `minimumSampleSize`, `duration`.

```typescript
const variant = posthog.getFeatureFlag('pricing-page-layout');
```

Track conversion with experiment + variant properties.

## Scroll Depth

Track 25/50/75/100% milestones. Push to `dataLayer` + `posthog.capture`. Use passive scroll listener.

## DataLayer Pattern

```typescript
function trackEvent(event: string, props: Record<string, unknown> = {}) {
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({ event, ...props });
  posthog.capture(event, props);
}
```

## Funnels

```typescript
const FUNNELS = {
  signupToActivation: { steps: ['page_viewed /signup', 'signup_completed', 'feature_activated'], window: '7d' },
  visitToPurchase: { steps: ['page_viewed /', 'cta_clicked pricing', 'purchase_completed'], window: '30d' },
};
```

## CSP for Analytics

```
script-src: https://www.googletagmanager.com https://www.google-analytics.com https://*.posthog.com
connect-src: https://www.google-analytics.com https://analytics.google.com https://*.posthog.com https://*.sentry.io
```

## Full Analytics Auto-Provision (***MANDATORY — ALL THREE***)

### Sentry (Error Tracking + Performance)

Every project gets Sentry from day one. Missing `@sentry/cloudflare` (Workers) or `@sentry/node` → install SDK + wrap entry point + create project via `mcp__sentry__create_project` (org: megabyte-labs, team: megabyte-labs, platform: javascript) → set `SENTRY_DSN` via `wrangler secret put`. Set `tracesSampleRate`; `app.onError()` → `captureException` with route + userId tags; breadcrumbs before risky ops; `SENTRY_RELEASE` for deploy tracking.

### PostHog (Product Analytics + Feature Flags + Session Recording)

Every HTML page gets PostHog snippet: `persistence:'memory'` (cookie-free) · `capture_pageview:true` · `capture_pageleave:true` · `autocapture:true`. CSP: script-src + connect-src for PostHog API host. Key as `POSTHOG_KEY` env var or inline for static HTML. PostHog Cloud is the rail (`us.i.posthog.com` / `eu.i.posthog.com`) — self-hosting is DEPRECATED for production (hobby-only ≤300k events/mo, unsupported, no new K8s, cloud-only features) per PostHog + our `never self-host` doctrine (skill 28).

Events: `page_viewed`, `cta_clicked`, `form_submitted`, `donate_click`, `newsletter_signup`, `scroll_depth`.

### GA4/GTM (Marketing Analytics + Tag Management)

Every HTML page gets GTM container (head script + noscript iframe after body). GTM container ID: `get-secret GTM_CONTAINER_ID` (Megabyte Labs). CSP:

- `script-src` — googletagmanager.com + google-analytics.com
- `connect-src` — analytics.google.com + region1.google-analytics.com
- `img-src` — googletagmanager.com + google-analytics.com

GA4 configured inside GTM (never standalone). Custom dimensions over separate events. 14-month retention. Google Signals enabled.

### Enforcement

Missing ANY of the three → add in same prompt. No page ships without all three firing. Every action: GA4 event + PostHog event + Sentry breadcrumb. CSP must allow all three domains. Verify in DevTools Network tab before marking deploy done.

## Verification Checklist

- GTM loads
- GA4 fires (DebugView)
- PostHog captures pageviews (Live Events)
- Sentry DSN set + errors captured (Sentry Issues dashboard)
- Custom events fire on interactions
- Feature flags resolve
- Session recording captures
- No duplicate events
- CSP allows all domains
- Scroll depth fires at milestones
- No cookies set (`persistence:'memory'`)

## Ownership

- **Owns** — GA4 config, GTM setup, PostHog SDK, feature flags, A/B tests, event taxonomy, funnels, session recording, scroll tracking, dataLayer architecture, cookie-free analytics, verification
- **Never owns** — Error tracking config (→ 13 Sentry), payments (→ 18), email marketing (→ 13 Listmonk), growth strategy (→ 13), deployment (→ 08), SEO (→ 28)
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall