heymegabyte/agent-skills / 13-observability-and-growth
observability-and-growth
VerifiedFull 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 6.8 KB |
| activation-funnel.md | markdown | 11.0 KB |
| analytics-configuration.md | markdown | 7.2 KB |
| conversion-optimization.md | markdown | 4.9 KB |
| email-marketing-and-listmonk.md | markdown | 8.1 KB |
| feature-flags-and-experiments.md | markdown | 6.6 KB |
| mcp-server-registry.md | markdown | 15.0 KB |
| sentry-alert-rules.md | markdown | 8.7 KB |
| square-payments.md | markdown | 13.3 KB |
| stripe-billing.md | markdown | 9.8 KB |
| user-feedback-collection.md | markdown | 8.9 KB |
| workers-tracing-otlp.md | markdown | 3.0 KB |
feature-flags-and-experiments.md
View on GitHub---
name: "Feature Flags and Experiments"
description: "PostHog feature flags and A/B testing. Server-side flag evaluation in Hono middleware, Angular directive for client-side flags, experiment setup with control/variants and statistical significance, gradual rollout patterns, and kill switches."
updated: "2026-04-23"
---
# Feature Flags and Experiments
## PostHog Server-Side Flags (Hono Middleware)
```typescript
// src/middleware/feature-flags.ts
import { PostHog } from 'posthog-node';
import type { Context, Next } from 'hono';
function createPostHog(env: Env): PostHog {
return new PostHog(env.POSTHOG_API_KEY, { host: 'https://us.i.posthog.com', flushAt: 1, flushInterval: 0 });
}
// Middleware: evaluate flags for authenticated user
async function featureFlagMiddleware(c: Context<{ Bindings: Env }>, next: Next): Promise<void> {
const userId = c.get('userId');
if (!userId) { await next(); return; }
const posthog = createPostHog(c.env);
const flags = await posthog.getAllFlags(userId, {
personProperties: { email: c.get('userEmail'), plan: c.get('userPlan') },
});
c.set('featureFlags', flags);
await posthog.shutdown();
await next();
}
// Route-level flag check
async function requireFlag(flagName: string, c: Context): Promise<boolean> {
const flags = c.get('featureFlags') as Record<string, boolean | string>;
return !!flags[flagName];
}
// Usage in route
app.get('/api/new-feature', featureFlagMiddleware, async (c) => {
if (!await requireFlag('new-dashboard', c)) {
return c.json({ error: 'Feature not available' }, 404);
}
// Feature implementation
return c.json({ data: 'new feature response' });
});
```
## Angular Feature Flag Directive
```typescript
// feature-flag.directive.ts
import { Directive, Input, TemplateRef, ViewContainerRef, OnInit, DestroyRef, inject } from '@angular/core';
import { FeatureFlagService } from './feature-flag.service';
@Directive({ selector: '[appFeatureFlag]', standalone: true })
export class FeatureFlagDirective implements OnInit {
@Input('appFeatureFlag') flagName = '';
@Input('appFeatureFlagElse') elseTemplate?: TemplateRef<unknown>;
private destroyRef = inject(DestroyRef);
constructor(
private templateRef: TemplateRef<unknown>,
private viewContainer: ViewContainerRef,
private flagService: FeatureFlagService,
) {}
ngOnInit(): void {
this.flagService.isEnabled(this.flagName).subscribe((enabled) => {
this.viewContainer.clear();
if (enabled) {
this.viewContainer.createEmbeddedView(this.templateRef);
} else if (this.elseTemplate) {
this.viewContainer.createEmbeddedView(this.elseTemplate);
}
});
}
}
// feature-flag.service.ts
import { Injectable, signal } from '@angular/core';
import { Observable, from, of } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';
import posthog from 'posthog-js';
@Injectable({ providedIn: 'root' })
export class FeatureFlagService {
private cache = new Map<string, Observable<boolean>>();
isEnabled(flag: string): Observable<boolean> {
if (!this.cache.has(flag)) {
this.cache.set(flag, of(posthog.isFeatureEnabled(flag) ?? false).pipe(shareReplay(1)));
}
return this.cache.get(flag)!;
}
getVariant(flag: string): string | boolean | undefined {
return posthog.getFeatureFlag(flag);
}
/** Force reload all flags (after login/plan change) */
reload(): void {
posthog.reloadFeatureFlags();
this.cache.clear();
}
}
// Template usage:
// <div *appFeatureFlag="'new-dashboard'; else oldDashboard">New UI</div>
// <ng-template #oldDashboard>Old UI</ng-template>
```
## A/B Experiment Setup
PostHog Dashboard: **Experiments → New Experiment**
1. **Name** — `"pricing-page-redesign"`
2. **Feature flag key** — `"pricing-page-variant"`
3. **Variants** — control (50%), test-a (25%), test-b (25%)
4. **Goal metric** — `upgrade_click` event
5. **Secondary** — `time_on_page` property
6. **Minimum sample** — 1000 per variant
7. **Significance threshold** — 95%
Client implementation:
```typescript
const variant = posthog.getFeatureFlag('pricing-page-variant');
// variant: 'control' | 'test-a' | 'test-b'
switch (variant) {
case 'test-a':
showRedesignedPricing();
break;
case 'test-b':
showMinimalPricing();
break;
default:
showOriginalPricing();
}
// Track conversion (automatically attributed to variant)
posthog.capture('upgrade_click', { plan: 'pro', source: 'pricing-page' });
```
## Gradual Rollout Pattern
PostHog Dashboard: **Feature Flags → New Flag**
### Release conditions
1. **Start** — 5% of users → monitor errors/feedback
2. **Day 2** — 25% → check metrics
3. **Day 5** — 50% → validate at scale
4. **Day 7** — 100% → full release
### Targeting
- **By property** — `plan = 'pro'` (beta users first)
- **By cohort** — `"internal-team"` → 100%, everyone else → rollout %
- **By email** — `*@megabyte.space` → always on (internal testing)
### Rollout automation via API
```typescript
async function updateRollout(flagKey: string, percentage: number, env: Env): Promise<void> {
await fetch(`https://us.posthog.com/api/projects/${env.POSTHOG_PROJECT_ID}/feature_flags`, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${env.POSTHOG_PERSONAL_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
key: flagKey,
filters: { groups: [{ rollout_percentage: percentage }] },
}),
});
}
```
## Kill Switch Pattern
Disables features instantly. Name convention: `kill-{feature}` (inverted logic).
- `kill-payments` → true = payments **DISABLED**
- `kill-signups` → true = signups **DISABLED**
```typescript
async function checkKillSwitch(feature: string, c: Context): Promise<boolean> {
const flags = c.get('featureFlags') as Record<string, boolean>;
return flags[`kill-${feature}`] === true;
}
// In route
app.post('/api/checkout', async (c) => {
if (await checkKillSwitch('payments', c)) {
return c.json({ error: 'Payments temporarily unavailable', code: 'MAINTENANCE' }, 503);
}
// Normal checkout flow
});
```
PostHog: toggle `kill-payments` to true → instant disable, no deploy, rolls back in <1 second.
## Experiment Analysis Checklist
1. Minimum 100 conversions per variant (not just impressions)
2. Run for full week minimum (captures day-of-week effects)
3. Check for novelty effect (flat after initial spike = novelty)
4. Statistical significance ≥ 95% before calling winner
5. Check segments: does variant win across all plans/devices?
6. Document: hypothesis, variants, metric, result, decision
7. Archive losing variant code. Ship winner. Clean up flag.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 119k | Updated | Claude CodeCodex | Verified | Install |
| 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: 118k | Updated | Claude CodeCodex | Verified | Install |