6 min read

How to Set Up Alerts for Feature Flag Impact in PostHog

You just rolled out a feature flag, and now you need to know if it's working—or breaking something. PostHog's alerts let you monitor the metrics that matter and get notified the moment a flag impacts user behavior. Here's how to set them up so you're not checking dashboards every five minutes.

Capture Flag Context in Your Events

The foundation of alert-worthy data is making sure your events include the feature flag state. When you capture events, PostHog needs to know which flag variant the user was seeing.

Add Flag State to Event Properties

When you send events to PostHog, include the feature flag state as a property. This lets you segment metrics by flag variant later. Use posthog.getFeatureFlag() to get the current variant, then attach it to your event.

javascript
const checkoutVariant = posthog.getFeatureFlag('new_checkout_flow');

posthog.capture('checkout_started', {
  amount: 99.99,
  checkout_variant: checkoutVariant,
  user_id: user.id
});
Capture events with flag state so you can segment metrics by variant later

Use Event Properties for Segmentation

Make sure the property name is consistent across all events you want to track. PostHog will let you filter by this property when building your metric insight.

javascript
const variant = posthog.getFeatureFlag('new_checkout_flow');

posthog.capture('checkout_started', { checkout_variant: variant });
posthog.capture('payment_entered', { checkout_variant: variant });
posthog.capture('purchase_completed', { checkout_variant: variant });
Use consistent property names across all relevant events
Watch out: If you capture events before the flag is loaded, the property will be undefined. Use posthog.onFeatureFlags() to wait for flags to load first.

Create a Metric Insight for Your Flag

Once you're capturing flag state with events, create an Insight that measures the metric you care about—conversion rate, session duration, whatever matters for this flag.

Build the Base Insight

Go to Insights > New insight and select your key metric event (e.g., purchase_completed). Set the aggregation to Count or Unique users. This gives you the baseline metric before you segment by flag.

javascript
posthog.onFeatureFlags(() => {
  const variant = posthog.getFeatureFlag('new_checkout_flow');
  
  posthog.capture('purchase_completed', {
    checkout_variant: variant,
    revenue: 99.99,
    timestamp: new Date().toISOString()
  });
});
Ensure flags are loaded before capturing events for accurate segmentation

Segment by Flag Variant

In your Insight, add a Breakdown by your flag property (e.g., checkout_variant). Now you'll see the metric split by control and treatment. This comparison is what you'll alert on.

javascript
// Query PostHog API to get metrics by flag variant
const response = await fetch(
  'https://YOUR_POSTHOG_INSTANCE/api/projects/YOUR_PROJECT_ID/insights/',
  {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${POSTHOG_API_KEY}`,
      'Content-Type': 'application/json'
    }
  }
);

const metrics = await response.json();
Access Insights via API to automate metric queries
Tip: Use a recent date range (last 7 days, last 24 hours) for your baseline. Old data won't predict how the flag is actually performing now.

Set Up Alerts on Metric Changes

Now that you have the metric segmented by flag, create an alert that fires when the metric deviates from your baseline.

Configure Alert Thresholds

In your Insight, click Alerts and choose your threshold type. Set it to alert if conversion drops below 5%, or session duration changes by more than 20%. PostHog checks thresholds on a schedule (hourly by default).

javascript
const alertPayload = {
  name: 'New checkout conversion below 5%',
  insight_id: INSIGHT_ID,
  condition: {
    type: 'threshold',
    value: 5,
    operator: 'below'
  },
  check_interval: 3600
};

const response = await fetch(
  `https://YOUR_POSTHOG_INSTANCE/api/projects/YOUR_PROJECT_ID/alerts/`,
  {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${POSTHOG_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(alertPayload)
  }
);
Create alerts programmatically via the PostHog API

Route Alerts to Slack or Email

Set notification channels in Settings > Integrations. Connect Slack or configure email alerts so your team gets notified immediately. Slack integration is fastest—alerts post to your channel in real time.

javascript
const alertUpdate = {
  enabled: true,
  notification_targets: [
    {
      type: 'slack',
      slack_channel: '#analytics',
      slack_webhook_url: 'https://hooks.slack.com/services/YOUR/WEBHOOK/URL'
    }
  ]
};

await fetch(
  `https://YOUR_POSTHOG_INSTANCE/api/projects/YOUR_PROJECT_ID/alerts/${ALERT_ID}/`,
  {
    method: 'PATCH',
    headers: {
      'Authorization': `Bearer ${POSTHOG_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(alertUpdate)
  }
);
Route alerts to Slack for immediate team visibility
Watch out: Alerts check on schedule, not in real time. If your flag launches at 5pm and you check hourly, you won't see problems until 6pm. For urgent rollouts, watch the dashboard live.

Common Pitfalls

  • Capturing events before feature flags load—flag state will be undefined and your segmentation won't work.
  • Setting thresholds too strict—alerting on every 1% change causes alert fatigue and masks real problems.
  • Not comparing the same metric across flag variants—you need control vs. treatment in the same Insight.
  • Alerting without a baseline—set expectations first (what's normal for this metric?), then alert on significant deviations.

Wrapping Up

You now have PostHog monitoring feature flag impact with real-time alerts. Your team will know the moment a flag affects user behavior—no manual dashboard checking required. If you want to track this automatically across tools, Product Analyst can help.

Track these metrics automatically

Product Analyst connects to your stack and surfaces the insights that matter.

Try Product Analyst — Free