If your event frequency drops 30% overnight, you want to know immediately—not in next week's metrics review. Maybe a feature broke, instrumentation failed, or users actually churned. Amplitude lets you set a threshold and get notified the instant your event count dips below it. Here's how to build that alert.
Instrument Your Event
You can't alert on what you don't track. Set up event tracking first.
Step 1: Initialize Amplitude and track the event
Install the Amplitude JavaScript SDK and initialize it with your API key. Then call amplitude.track() whenever the event happens—every time a user purchases, logs in, or uses the feature you're monitoring.
import * as amplitude from '@amplitude/analytics-browser';
amplitude.init('YOUR_API_KEY', { userId: 'user_123' });
// Track the event every time it happens
amplitude.track('Purchase', {
product_id: 'sku_456',
amount: 99.99,
currency: 'USD'
});Step 2: Verify events in the Debugger
Open your browser's Dev Tools > Amplitude > Debugger tab (or use Settings > Diagnostics in your Amplitude project). Confirm events are flowing with correct properties. If nothing appears, check that amplitude.init() runs before amplitude.track().
// Ensure identify() happens before track() for user cohorts
amplitude.identify(new amplitude.Identify()
.set('plan', 'premium')
.set('is_beta_user', true)
);
// Then track the event
amplitude.track('Feature Export Used', {
export_type: 'csv',
row_count: 5000
});product_id or feature_name) so you can filter alerts by category instead of alerting on all variants.Create an Alert in Amplitude Dashboard
Once events flow reliably, set up the alert rule.
Step 1: Build a frequency chart
Go to Home > Events, select your event (e.g., 'Purchase'), and create a chart. Choose Count or Uniques as your metric, and set the interval to Hour or Minute depending on your baseline volume. For example, if you expect 1000 purchases per hour, an hourly interval makes sense.
// Export raw events to validate frequency baseline
const exportEvents = async (eventName) => {
const response = await fetch('https://api.amplitude.com/events/2/export', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
start: '20240320T00',
end: '20240327T00',
event: [eventName]
})
});
const data = await response.json();
return data.events;
};
const events = await exportEvents('Purchase');
console.log(`Found ${events.length} Purchase events in past week`);Step 2: Configure the alert rule
Click Alerts at the top of your chart, then Create Alert. Set the condition: Alert when count falls below 800 per hour (use your actual baseline minus 10–20% buffer). Choose notification channels (Email, Slack, or PagerDuty) and list recipients.
// Example: Track with metadata to help diagnose why frequency changed
amplitude.track('Purchase', {
product_id: 'sku_123',
amount: 99.99,
payment_method: 'credit_card',
user_segment: 'premium' // Helps pinpoint if only one segment dropped
});Step 3: Save and test the alert
Toggle the alert On. Wait for the next hour boundary (Amplitude evaluates on the hour). To test, manually pause event tracking for 10 minutes, then resume. You should receive a notification. Once verified, the alert runs continuously.
// Simulate alert test: pause tracking
let trackingEnabled = false;
function handleUserAction(action) {
if (trackingEnabled) {
amplitude.track(action, { timestamp: Date.now() });
}
}
// After testing, re-enable
trackingEnabled = true;Automate Alerts Across Projects (Optional)
If you manage multiple Amplitude projects or need alerts as code, use the Management API.
Step 1: Authenticate with API credentials
Go to Settings > Projects > API Credentials and copy your API Key and Secret Key. You'll also need your Workspace ID (visible in the URL). Use these to authenticate API requests with Basic Auth.
const API_KEY = process.env.AMPLITUDE_API_KEY;
const SECRET_KEY = process.env.AMPLITUDE_SECRET_KEY;
const WORKSPACE_ID = 'YOUR_WORKSPACE_ID';
const auth = Buffer.from(`${API_KEY}:${SECRET_KEY}`).toString('base64');
const headers = {
'Authorization': `Basic ${auth}`,
'Content-Type': 'application/json'
};
module.exports = { headers, WORKSPACE_ID };Step 2: Create alerts programmatically
POST to the alerts endpoint with the event name, threshold, and notification channels. This lets you create matching alerts across staging and production, or bulk-configure alerts for multiple events.
const axios = require('axios');
const { headers, WORKSPACE_ID } = require('./auth');
const createAlert = async (eventName, threshold) => {
const payload = {
name: `${eventName} Frequency Alert`,
description: `Alert if ${eventName} count drops below ${threshold}/hour`,
event: eventName,
threshold: threshold,
comparison: 'below',
time_window: 'hour',
notification_channels: ['email'],
recipients: ['[email protected]']
};
const response = await axios.post(
`https://api.amplitude.com/api/v1/workspaces/${WORKSPACE_ID}/alerts`,
payload,
{ headers }
);
console.log(`Alert created: ${response.data.alert_id}`);
return response.data;
};
await createAlert('Purchase', 800);Common Pitfalls
- Setting the threshold exactly at your baseline—normal variance will trigger false alerts. Always use 10–20% buffer below your realistic low point.
- Creating alerts on events with sparse data—if an event fires 5 times per hour, a threshold of 4 is worthless. Ensure you have sufficient baseline volume first.
- Forgetting to document why an alert exists—when it fires months later, your team won't know if it's a known issue or a critical gap.
- Using Amplitude-only alerts without fallback monitoring—if Amplitude's notification system fails, you won't know about the frequency drop.
Wrapping Up
You now have real-time visibility into event frequency changes. When users stop purchasing, stop signing up, or stop using a feature, you'll know in minutes—not days. If you want to track this automatically across tools, Product Analyst can help.