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.
const checkoutVariant = posthog.getFeatureFlag('new_checkout_flow');
posthog.capture('checkout_started', {
amount: 99.99,
checkout_variant: checkoutVariant,
user_id: user.id
});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.
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 });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.
posthog.onFeatureFlags(() => {
const variant = posthog.getFeatureFlag('new_checkout_flow');
posthog.capture('purchase_completed', {
checkout_variant: variant,
revenue: 99.99,
timestamp: new Date().toISOString()
});
});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.
// 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();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).
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)
}
);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.
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)
}
);Common Pitfalls
- Capturing events before feature flags load—flag state will be
undefinedand 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.