Streaks API
The streak tracking API for consumer web and mobile apps
Add daily or weekly streaks to your app in under an hour. Trophy handles timezone logic, daylight savings transitions, and freeze mechanics out of the box. Scales to millions of users.
Quickstart
Quickstart: track and read a streak
Send a metric event to extend a streak, then fetch the user’s current streak length, expiry, and history. Trophy handles timezone evaluation and freeze consumption automatically.
import { TrophyApiClient } from "@trophyso/node";
const trophy = new TrophyApiClient({ apiKey: process.env.TROPHY_API_KEY });
// 1. Track activity that powers the streak
const eventResponse = await trophy.metrics.event("lessons", {
user: { id: "user-123" },
value: 1,
});
console.log("Current streak:", eventResponse.currentStreak?.length);
// 2. Fetch full streak state for UI (length, expires, history)
const streak = await trophy.users.streak("user-123");
console.log("Length:", streak.length);
console.log("Expires:", streak.expires);
console.log("History periods:", streak.streakHistory?.length);
// 3. Optionally grant a freeze so one missed day does not reset progress
await trophy.admin.streaks.freezes.create({
freezes: [{ userId: "user-123" }],
});Edge cases
Handling timezones, DST and grace periods
Trophy handles timezones, daylight savings transitions, and grace periods automatically. Every streak is evaluated in the user's own local timezone, and clock changes on daylight savings dates will not break or extend a streak by accident.
import { TrophyApiClient } from "@trophyso/node";
const trophy = new TrophyApiClient({ apiKey: process.env.TROPHY_API_KEY });
// Track an event. Trophy evaluates the streak in the user's local timezone
// and handles daylight savings transitions automatically.
const { currentStreak } = await trophy.metrics.event("lessons", {
user: {
id: "user-123",
tz: "America/New_York"
},
value: 1,
});Buy vs. build
Why use Trophy's streak API?
Streak mechanics are deceptively complex. Timezone handling, daylight savings transitions, freeze logic, and period boundaries each introduce edge cases that are hard to test exhaustively and expensive to maintain over time.
Integration Time
Reliability
Scalability
Ongoing Maintenance
Feature Development
Concepts
How a daily streak works
A streak counts consecutive periods of activity. Most implementations track the same core fields: a current streak count (current_streak), a longest or “best” streak (longest_streak), and the date the user was last active (last_active_date). Trophy’s API exposes these same concepts as length, started, expires, and streakHistory.
| Generic concept | Trophy field |
|---|---|
| Current streak count | length |
| Streak start date | started |
| When the streak breaks if not extended | expires |
| Past streak periods (and best streak) | streakHistory |
Increment logic. If the user was already active today, the streak stays the same. If they return the next calendar day, the streak increments by one. If they skip more than one period, the streak resets to zero.
Timezones. Store timestamps in UTC, but evaluate streaks in the user’s local time. A user who logs activity at 11:55 PM and again at 12:05 AM should keep their streak, not lose it. Trophy handles timezone-aware evaluation and daylight savings transitions automatically.
Streak freezes. A freeze lets a user skip a required period entirely without resetting progress. Trophy can grant and consume freezes automatically, and you can manage them programmatically through the streak freeze API.
Endpoints
Streak API endpoints
Trophy tracks streaks and sends streak reminder push notifications and emails through a single API call. Use Trophy's streak tracking API to record consecutive user activity, maintain daily and weekly streak history, and manage freeze mechanics automatically from the metric events you send.
Send a metric event to track user activity and power streaks.
Path Parameters
keystringrequiredUnique reference of the metric as set when created.
Request Body
userUserrequiredThe user that triggered the event (must include id).
valuenumberrequiredThe value to add to the user's current total for the given metric.
Response
eventIdstringUnique identifier for the created event.
totalnumberThe user's new total for this metric.
currentStreakStreakThe user's current streak status.
import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
// Track a user event
await trophy.metrics.event("lessons", {
user: {
id: "user-123"
},
value: 1
}
);
// This single event:
// - Records user activity
// - Computes streak data
// - Returns new streak data
Get a user's streak data including current length, frequency, and history.
Path Parameters
idstringrequiredID of the user.
Query Parameters
historyPeriodsintegerNumber of past streak periods to include in streakHistory (default: 7).
Response
lengthnumberCurrent streak length.
frequencystringStreak frequency: "daily", "weekly", or "monthly".
starteddateDate the current streak started.
expiresdateWhen the streak will break if not extended.
streakHistoryStreakPeriod[]Array of past streak periods with lengths.
import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
// Fetch user streak data
const streak = await trophy.users.streak("user-123");
// Response:
// {
// length: 7,
// frequency: "daily",
// started: "2025-04-02",
// periodStart: "2025-03-31",
// expires: "2025-04-12",
// rank: 5,
// streakHistory: [...]
// }Create streak freezes for multiple users. Freezes prevent streak loss when users miss a period.
Request Body
freezesarrayrequiredArray of objects with userId to create freezes for.
Response
issuesIssue[]Array of warnings or errors for each freeze request.
import { TrophyApiClient } from '@trophyso/node';
const trophy = new TrophyApiClient({
apiKey: 'YOUR_API_KEY'
});
// Create streak freezes
await trophy.admin.streaks.freezes.create({
freezes: [
{ userId: "user-123" }
]
});
// Protects streak from breakingBuilt for production workloads
Reliable infrastructure designed for performance at scale.
- Uptime SLA
- 99.9%
- p95 API Latency
- 200ms
- Monthly API Requests
- 180M
- Users Tracked
- 1M+
How do daily streaks work?
Trophy's daily streak tracking API records consecutive periods of user activity automatically. When you send a metric event, Trophy extends the user's streak for that period. If a user misses a day, week, or month, the streak resets.
Can I configure streak frequency?
Yes. Streaks can be configured as daily, weekly, or monthly in the Trophy dashboard. A daily streak requires activity every day, weekly requires at least one activity per week, and so on.
What is the streak freeze API?
Trophy can automatically grant and consume streak freezes to keep streaks alive. Trophy's streak freeze API lets you programmatically manage users' streaks with more control. For example grant an extra freeze to premium users and Trophy applies it automatically the next time a user misses a day.
How do I build a habit-tracking feature with streaks?
Send a metric event to Trophy each time a user completes a target action and Trophy's streak API handles the rest — consecutive activity tracking, timezone-aware expiration and daylight savings while tracking streak history. Fetch streak data via the API to render streak UI in your frontend.
How do streaks improve user retention?
Streaks create a psychological commitment loop where users return to avoid breaking their streak, which drives daily active usage and builds habitual engagement. Across Trophy's platform, apps using streak freeze features average 17-day streaks for users who pass the 7-day mark, compared to 11 days for apps without freezes. Trophy can also send streak reminder emails and push notifications to users who are close to breaking their streak to increase average streak length and retention.
Can I show streaks in React, React Native, or mobile apps?
Yes. Adding a mobile app streak feature with Trophy uses server-side SDKs (Node.js, Python, Go, Java, PHP, Ruby, .NET) to manage streak logic on your backend. The API returns streak length, frequency, and expiration data that you can render in any frontend — React, React Native, Next.js, Swift, Kotlin, Flutter, or any other framework.