Feature flags let you ship changes to a subset of users, but you need to see if they're actually working. PostHog makes this straightforward—by tracking events tied to your flags and querying them, you can build dashboards that show control vs. variant performance side-by-side.
Capture Events When a Feature Flag is Exposed
The foundation is simple: whenever a user hits your flagged feature, capture an event and tag it with the flag name and variant. This gives you a timestamped record tied to user identity.
Check the flag and capture an event in the same request
When your code evaluates a feature flag, immediately capture an event with the flag details. Use the posthog.isFeatureEnabled() method to check the flag, then posthog.capture() to log an exposure event with the flag name and variant as properties.
import posthog from 'posthog-js';
const flagKey = 'checkout-redesign';
const isEnabled = posthog.isFeatureEnabled(flagKey);
const variant = posthog.getFeatureFlag(flagKey);
if (isEnabled) {
posthog.capture('checkout_page_viewed', {
feature_flag: flagKey,
flag_variant: variant,
timestamp: new Date().toISOString()
});
// Render the new checkout
} else {
posthog.capture('checkout_page_viewed', {
feature_flag: flagKey,
flag_variant: 'control',
timestamp: new Date().toISOString()
});
// Render the old checkout
}Include the flag variant in all downstream events
For conversion and goal events (like purchase_completed), add the same flag and variant properties. This ties every user action back to which variant they saw, making it easy to attribute outcomes.
const flagVariant = posthog.getFeatureFlag('checkout-redesign');
posthog.capture('purchase_completed', {
amount: cartTotal,
feature_flag: 'checkout-redesign',
flag_variant: flagVariant || 'control',
product_count: items.length
});isFeatureEnabled() but forget to capture the initial exposure event, you'll miss users in the control group. Capture an event regardless of whether the flag is true or false.Query and Visualize Flag Performance in PostHog Insights
Once events are flowing with flag properties, use PostHog's Insights to filter, segment, and compare. You can see raw event counts, conversion rates, or trends over time—all segmented by variant.
Create an Insight segmented by flag variant
Go to Insights and create a new Trends chart. Select your conversion event (e.g., purchase_completed), then click Add breakdown and choose the flag_variant property. PostHog renders separate line series for 'control' and your variant, making differences obvious.
// In PostHog UI: Insights > Trends
// Event: purchase_completed
// Breakdown by: flag_variant
// Time range: Last 7 days
// This generates SQL under the hood:
// SELECT flag_variant, COUNT(*) as count, toDate(timestamp) as date
// FROM events
// WHERE event = 'purchase_completed' AND flag_variant IN ('control', 'variant_1')
// GROUP BY flag_variant, dateBuild a dashboard to compare metrics side-by-side
Create a Dashboard and add multiple Insights: one for conversion rate by variant, one for average order value, and one for page views. Use the same flag_variant breakdown on each. This gives you a real-time command center for flag performance.
// Example dashboard structure:
// Card 1: Conversion rate by variant
// posthog.capture('purchase_completed', {...})
// Breakdown: flag_variant
// Metric: Count / Unique users
// Card 2: Avg order value by variant
// Breakdown: flag_variant
// Property average: amount
// Card 3: Checkout views by variant
// Event: checkout_page_viewed
// Breakdown: flag_variant
// Aggregation: Countcheckout_page_viewed → purchase_completed, add flag_variant as a breakdown, and PostHog shows control vs. variant completion at each step.Use PostHog Experiments for Statistical Rigor
If you want confidence intervals and statistical significance tests, PostHog's Experiments feature automates the analysis. It tracks variant exposure and outcomes, then calculates p-values.
Create an Experiment linked to your feature flag
In Experiments, click New experiment and select the feature flag you want to measure (e.g., 'checkout-redesign'). Choose a primary metric—PostHog will track exposures and calculate if the variant significantly outperforms the control.
// PostHog Experiments automatically tracks:
// 1. Feature flag exposures (from posthog.isFeatureEnabled() calls)
// 2. Primary metric events (purchase_completed)
// 3. Calculates lift %, p-value, and confidence intervals
// Your code captures the standard events:
posthog.capture('purchase_completed', {
amount: 99.99,
feature_flag: 'checkout-redesign',
flag_variant: posthog.getFeatureFlag('checkout-redesign') || 'control'
});
// PostHog's Experiment UI handles the stats—no manual calculation neededCommon Pitfalls
- Forgetting to capture the baseline (control) variant—only logging when the flag is true. You need exposure events for both control and variant to calculate a true comparison.
- Not including the
flag_variantproperty in every downstream event. If you log purchases without the flag metadata, you can't segment by variant later—your dashboard will be incomplete. - Running an Experiment while your code still uses
isFeatureEnabled()to route logic. This causes double-counting and skewed results. Choose one or the other. - Expecting instant results. Feature flag experiments need time to accumulate data. With low traffic, you may not hit statistical significance for days or weeks—patience matters.
Wrapping Up
By capturing flag exposures and variants in events, then querying with PostHog Insights or Experiments, you get a clear picture of how your feature affects user behavior. Whether you use Trends, Funnels, or full Experiments, the data flow is the same: instrument the flag check, tag the events, and visualize. If you want to track this automatically across tools, Product Analyst can help.