Session length directly reflects how engaged your users are with your product. Long sessions indicate sticky features; short sessions signal friction or incomplete user journeys. Amplitude makes it straightforward to visualize this metric across your entire user base or drill down into specific cohorts.
Visualize Session Length in the Events Dashboard
The quickest way to see session patterns is through Amplitude's Events dashboard, which has a built-in Sessions metric.
Go to Events and select the Sessions metric
Open Analytics > Events in your Amplitude project. In the events list, search for or select Sessions. Amplitude automatically aggregates session data, so you'll immediately see a time-series chart of average session duration.
// Amplitude SDK automatically tracks sessions
import * as amplitude from '@amplitude/analytics-browser';
amplitude.init('YOUR_API_KEY');
// Sessions are tracked automatically by default
// No additional code needed — just ensure defaultTracking is enabledFilter by user properties or events
Add a Where clause to filter sessions by user properties (e.g., plan = 'enterprise', signup_date in the last 30 days). This narrows your view to specific cohorts. You can also filter by events that occurred during the session.
// Log events with custom properties to enable filtering
amplitude.logEvent('feature_used', {
plan: 'enterprise',
feature: 'custom_dashboards',
timestamp: Date.now()
});
// Then filter by these properties in the dashboardSegment by a user property to compare cohorts
Click + Segment and choose a property like user_type, plan, or country. Amplitude will display separate session length bars for each value, letting you spot if enterprise users have longer sessions than free-tier users.
// Set user properties early to enable segmentation
amplitude.setUserProperties({
plan: 'enterprise',
user_type: 'account_owner',
company_size: 50
});
// These properties appear in the Segment dropdownUse the REST API for Programmatic Access
If you need to export session data for custom analysis, use Amplitude's REST API to pull detailed session information into your own pipeline.
Generate an API key and prepare your request
Navigate to Settings > API Keys and note your API Key and Secret Key. You'll use these to authenticate REST API calls. The events endpoint returns raw session data with duration, user IDs, and timestamps.
const apiKey = 'YOUR_API_KEY';
const secretKey = 'YOUR_SECRET_KEY';
const projectId = 'YOUR_PROJECT_ID';
// Construct the authorization header
const auth = Buffer.from(`${apiKey}:${secretKey}`).toString('base64');
const headers = {
'Authorization': `Basic ${auth}`,
'Accept': 'application/json'
};Query session data via the events endpoint
Call the /events endpoint with a date range. The response includes session duration (in milliseconds), user ID, device info, and more. Parse the session_length field to calculate average, percentiles, or distributions.
async function getSessionData() {
const url = `https://api.amplitude.com/2/events?start=2026-03-01&end=2026-03-26`;
const response = await fetch(url, {
method: 'GET',
headers: {
'Authorization': `Basic ${auth}`,
'Accept': 'application/json'
}
});
const data = await response.json();
// Extract session lengths
const sessions = data.events.map(e => ({
user_id: e.user_id,
session_length: e.session_length,
timestamp: e.event_time
}));
return sessions;
}
getSessionData();Analyze the data in your application
Once you have the raw session data, calculate statistics like median, p95, or breakdowns by user segment. Store the results in your own database or visualization tool (Metabase, Tableau, etc.) for deeper analysis.
function analyzeSessionLength(sessions) {
const durations = sessions.map(s => s.session_length / 1000);
const sorted = durations.sort((a, b) => a - b);
const median = sorted[Math.floor(sorted.length / 2)];
const p95 = sorted[Math.floor(sorted.length * 0.95)];
const average = durations.reduce((a, b) => a + b, 0) / durations.length;
console.log(`Average session: ${average.toFixed(2)}s`);
console.log(`Median session: ${median.toFixed(2)}s`);
console.log(`95th percentile: ${p95.toFixed(2)}s`);
return { average, median, p95 };
}offset and limit parameters to avoid timeouts.Common Pitfalls
- Session timeout is 30 minutes by default — if your users have long pauses, sessions will split unexpectedly. Check your timeout setting in Project Settings.
- The free tier of Amplitude limits historical data access. If you're querying months of data, you may hit quotas or find older sessions excluded.
- Sessions tracked on different devices or after app force-closes create new session IDs, so a single user might have many short sessions. This can skew your average downward.
- UTC timezone matters — always specify your date range in UTC when using the REST API, or filter by user timezone if comparing across regions.
Wrapping Up
Session length is a proxy for user engagement. By visualizing it in the Amplitude dashboard or exporting it via the REST API, you can identify which features, user cohorts, or user journeys keep people in your product. If you want to track this automatically across tools, Product Analyst can help.