Your DAU/MAU ratio tells you whether users are coming back. If 40% of your monthly users are active today, you're getting loyal engagement—but if it's 5%, users aren't returning. Amplitude can show you this ratio directly in your dashboard, and you can calculate it programmatically via the API.
Verify User Tracking with the Amplitude SDK
Before visualizing DAU/MAU, confirm that Amplitude is tracking unique users correctly. You need user_id set consistently for every event.
Initialize the Amplitude SDK with a persistent user_id
Set up the JavaScript SDK in your app and identify users on login. Amplitude uses user_id to count unique daily and monthly active users. This value must persist across sessions.
import * as amplitude from '@amplitude/analytics-browser';
amplitude.init('YOUR_API_KEY', {
userId: currentUser.id
});
// Track events with the user context
amplitude.track('page_view', {
page: 'dashboard'
});Handle logged-in and anonymous users
Set user_id when the user logs in. For anonymous users, Amplitude falls back to device_id. If a user logs in later, call setUserId() to consolidate their sessions.
// On login
if (user && user.id) {
amplitude.setUserId(user.id);
}
// On logout
amplitude.setUserId(null); // Clear user contextVerify tracking in the Amplitude dashboard
Go to Analytics > User Sessions, search for a known user by their ID, and confirm their events appear. Check the User Lookup tab for the most recent event timestamp.
device_id, Amplitude counts an anonymous visitor and the same logged-in user as two separate monthly users, inflating MAU.Create a DAU/MAU Visualization in Your Dashboard
Amplitude's Users chart automatically counts daily and monthly active users. You can overlay both on the same chart to see engagement trends.
Add a Users chart to track active users
Click + Add Chart and select Users. Set the Time Window to at least 30 days to capture a full monthly baseline. Leave Event blank to count all active users regardless of which events they trigger.
Add a second series for monthly baseline
In the chart, click + Add Series and select Users again. Set the first series to group by Day and the second by Month. This lets you compare daily peaks against the monthly baseline.
// After building the chart in Amplitude UI, pull the data via API
const API_KEY = process.env.AMPLITUDE_API_KEY;
const SECRET_KEY = process.env.AMPLITUDE_SECRET_KEY;
const auth = Buffer.from(`${API_KEY}:${SECRET_KEY}`).toString('base64');
const response = await fetch(
'https://api.amplitude.com/api/2/events?start=2024-03-01&end=2024-03-31&limit=10000',
{ headers: { 'Authorization': `Basic ${auth}` } }
);
const data = await response.json();
console.log('Events:', data.data.events.length);Segment by user properties if needed
Click + Add Filter and select a Cohort or event property (e.g., plan_type, country) to compare DAU/MAU across customer segments. This reveals whether engagement differs between free and paid users.
Calculate DAU/MAU Programmatically with the REST API
For automated reporting or external dashboards, query the Amplitude Events API to fetch user counts and calculate the ratio yourself.
Query the Amplitude Events API for a date range
Use the Events API with date parameters to export all events for a month. Parse the response to extract unique user_id values per day and for the entire period.
const axios = require('axios');
const API_KEY = process.env.AMPLITUDE_API_KEY;
const SECRET_KEY = process.env.AMPLITUDE_SECRET_KEY;
const auth = Buffer.from(`${API_KEY}:${SECRET_KEY}`).toString('base64');
const response = await axios.get('https://api.amplitude.com/api/2/events', {
params: {
start: '2024-03-01',
end: '2024-03-31',
limit: 10000
},
headers: { 'Authorization': `Basic ${auth}` }
});
const events = response.data.data.events;
console.log(`Fetched ${events.length} events`);Aggregate users by day and month
Count unique user_id values for each day and the entire month using a Set. This gives you the daily and monthly active user counts.
const dailyUsers = new Map(); // YYYY-MM-DD -> Set of user_ids
const monthlyUsers = new Set();
for (const event of events) {
const date = event.event_time.split('T')[0]; // Extract date
const userId = event.user_id;
if (!dailyUsers.has(date)) {
dailyUsers.set(date, new Set());
}
dailyUsers.get(date).add(userId);
monthlyUsers.add(userId);
}
const lastDay = '2024-03-31';
const dau = dailyUsers.get(lastDay)?.size || 0;
const mau = monthlyUsers.size;
console.log(`DAU (${lastDay}): ${dau}`);
console.log(`MAU (Mar 2024): ${mau}`);
console.log(`Ratio: ${((dau / mau) * 100).toFixed(1)}%`);Common Pitfalls
- Counting
device_idinstead ofuser_idinflates MAU—an anonymous session plus the same logged-in user counts as two users - Defining MAU inconsistently (rolling 30 days vs calendar month) makes month-to-month comparisons meaningless
- Forgetting to exclude test accounts and internal team activity will skew your ratio lower
- Using a chart time window shorter than 30 days makes MAU artificially low relative to DAU
Wrapping Up
DAU/MAU tells you if users are staying engaged. Use Amplitude's Users chart to visualize both metrics side-by-side, then query the API if you need automated reporting. If you want to track this metric across multiple tools and dig into what's driving engagement changes, Product Analyst can help.