Skip to main content

Overview

SuperTokens Core provides built-in active user tracking that automatically updates user activity timestamps and allows you to query active user counts for any time period.

Features

Automatic Tracking

Activity updated during session operations

Flexible Queries

Count users active in any time period

App-Level Storage

Stored per app, not per tenant

How It Works

Automatic Updates

Active user timestamps are automatically updated during:
  • Session Creation: When a user signs in
  • Session Verification: When an access token is verified
  • Session Refresh: When tokens are refreshed
From io/supertokens/ActiveUsers.java:15-22:
Updates are fire-and-forget. Errors are silently ignored to prevent blocking session operations.

Counting Active Users

From io/supertokens/ActiveUsers.java:34-38:

Example: Common Time Periods

Manual Updates

While updates are automatic during session operations, you can manually update activity:

Use Cases for Manual Updates

  • API requests that don’t create/verify sessions
  • Background jobs or scheduled tasks
  • Mobile app foreground/background transitions
  • WebSocket connections
  • Server-to-server authentication

Account Linking Behavior

From io/supertokens/ActiveUsers.java:40-53: When accounts are linked, activity is consolidated:
When accounts are linked, the recipe user’s activity record is deleted and the primary user’s activity is updated. This prevents double-counting.

Storage Scope

Active users are tracked at the app level, not per tenant. The count includes all users active in any tenant within the app.
Active user data is stored in the public tenant storage:

Building Analytics Dashboard

Complete Analytics Example

Example Output

Time-Based Cohort Analysis

Performance Considerations

Database Indexing

Active users table should have an index on:
  • app_id + last_active_time for fast range queries
  • user_id for efficient updates

Caching Strategy

For high-traffic applications, cache active user counts:

Common Metrics

Key Performance Indicators

DAU/MAU Ratio

Stickiness: Measures how often users return. Higher is better.Formula: (DAU / MAU) × 100%Good: >20%

DAU/WAU Ratio

Weekly Engagement: How active users are within a week.Formula: (DAU / WAU) × 100%Good: >40%

WAU/MAU Ratio

Monthly Engagement: Weekly activity relative to monthly users.Formula: (WAU / MAU) × 100%Good: >50%

User Growth

Growth Rate: Change in active users over time.Formula: ((Current MAU - Previous MAU) / Previous MAU) × 100%

Best Practices

1

Don't Query Too Frequently

Cache results for at least 5-15 minutes to reduce database load
2

Use Appropriate Time Windows

Match time windows to your product’s usage patterns (daily app vs. weekly app)
3

Track Trends Over Time

Store historical counts to analyze growth trends
4

Segment by Cohort

Combine with user metadata to analyze different user segments
5

Monitor Database Performance

Ensure active users table has proper indexes

Limitations

Active user tracking has some limitations:
  • App-level only: Cannot query per-tenant active users directly
  • No deduplication across time: A user active on Day 1 and Day 7 counts twice in a 7-day count
  • Update failures silenced: Errors are ignored to prevent blocking session operations

Historical Data Storage

For long-term analytics, periodically snapshot counts:

Integration with Monitoring