6 min read

How to Set Up Alerts for Session Length in Amplitude

When your users start dropping off earlier, you need to know about it before your retention metrics tank. Amplitude automatically tracks session length, but the data sitting in your dashboard doesn't help if you're not watching. Setting up alerts on session length gives you early warning when something's changed—whether it's a product bug, a new feature that's confusing users, or just seasonal dips.

Verify Session Tracking Is Active

Session length is built into Amplitude, but you need to confirm the SDK is initialized correctly to capture sessions.

Initialize the Amplitude SDK with default session settings

The JavaScript SDK automatically creates sessions—a new one starts when the user first engages and ends after 5 minutes of inactivity. Verify the SDK is set up in your app, and use getSessionId() to confirm sessions are being tracked.

javascript
import * as amplitude from '@amplitude/analytics-browser';

amplitude.init('YOUR_API_KEY', {
  userId: 'user_123',
  sessionTimeout: 300000  // 5 minutes (default)
});

// Track an event - session ID is attached automatically
amplitude.track('page_view');

// Verify session is active
const sessionId = amplitude.getSessionId();
console.log('Active session:', sessionId);
The SDK includes session context in every event automatically—no extra config needed.

Confirm sessions appear in the Events tab

Go to Events > Event Explorer and look at any event's properties. You should see [session_id] listed. If it's missing, your SDK may not be initialized or events aren't being sent.

Create a Session Length Chart

You'll build a chart that tracks average session duration, then set a threshold alert on it.

Build a segmentation chart for session length

Open Events > Segmentation and click New. In the Metrics dropdown, select Session Length. Amplitude calculates this from the duration of each user session automatically—you don't need to define it.

Choose your aggregation method

Select Average for typical behavior, Median to avoid outliers, or Min/Max to catch edge cases. For most teams, average session length works well. Set your time range to 7 days to establish a baseline.

Segment by user properties for cohort-specific alerts

Click Segment by and select a user property like Plan or Region to break down session length by user type. This helps you catch drops in specific cohorts (e.g., premium users might spend more time than free users).

javascript
// Set user properties early so they're available for segmentation
amplitude.setUserProperties({
  'plan': 'premium',
  'region': 'us-west',
  'account_age_days': 45
});

// These properties appear in Segmentation dropdowns
amplitude.track('session_start');
User properties populate in the Segmentation UI and let you break down session length by cohort.
Tip: Median session length is more stable than average when you have users with unusually long sessions (like someone who left their tab open). Use median if your data has outliers.

Set Up and Test Your Alert

With your chart ready, you'll configure the alert threshold and choose how you're notified.

Click the Alert button and set your threshold

In the top right of your chart, click Alert. Choose your condition: use < (less than) to alert when session length drops. For example, if your current average is 5 minutes, alert when it dips below 3 minutes.

Set the check frequency and notification channel

Choose how often Amplitude checks the condition (hourly, daily, weekly). Pick your notification method: Email, Slack, or webhook. Slack is fastest for team visibility—alerts hit your channel in real time.

Test your alert and refine the threshold

Use Test Alert to make sure the notification works. If you get false positives, adjust your threshold higher. If you never see alerts, lower it. Most teams find a 15–20% drop from baseline is the right trigger.

Query session metrics programmatically using the REST API

For custom dashboards or external monitoring, use Amplitude's REST API to fetch session data. This is useful if you want to integrate session length into your own alert system.

javascript
const fetch = require('node-fetch');

const options = {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    data_source: 'events',
    measurements: [
      { expression: 'sessions', label: 'total_sessions' },
      { expression: 'sessions_duration', label: 'avg_session_ms' }
    ],
    group_by: [{ type: 'event_time', value: 'day' }],
    limit: 7
  })
};

const response = await fetch('https://api.amplitude.com/2/events', options);
const data = await response.json();

// Convert milliseconds to seconds for readability
const avgSessionSeconds = data.data.aggregations[0][1].value / 1000;
console.log(`Average session: ${avgSessionSeconds}s`);
The REST API returns session duration in milliseconds—divide by 1000 to get seconds.
Watch out: Session length is stored in milliseconds in Amplitude's database but displayed as seconds in the UI. When setting thresholds via API, remember 180,000 ms = 3 minutes, not 3 seconds.

Common Pitfalls

  • Not accounting for your session timeout—if users pause between actions, their session may split into multiple short sessions instead of one long one. Adjust the timeout in the SDK if needed.
  • Ignoring platform differences—web sessions are typically longer than mobile. Set separate alerts for web and app, or segment by platform.
  • Setting thresholds too tight—alerting on every 5% drop leads to alert fatigue. Use historical data to set realistic baselines (usually 15–20% drops matter).
  • Forgetting milliseconds when using the API—Amplitude measures duration in milliseconds, so always divide by 1000 when comparing to the UI or setting thresholds.

Wrapping Up

You now have session length monitoring in place and will get notified when users start dropping off earlier than normal. The key is setting thresholds based on your actual baseline data and segmenting by user type if different cohorts behave differently. If you want to track this metric across multiple tools and centralize alerting, Product Analyst can help.

Track these metrics automatically

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

Try Product Analyst — Free