Streaks API
The API for streaks
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. Start for free, scale 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" }],
});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 (sometimes called a “grace day”) protects a streak when a user misses a single period, so one skipped day does not reset their 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 breakingLightning-fast integration
Simple APIs you'll love
Use our pre-built gamification platform to effortlessly build retentive user experiences. Get a team that's 100% focused on retention.
- Type-safe SDKs.
- We spend time worrying about abstractions and let you focus on what matters: building a great experience for your users.
- Intuitive documentation.
- Documentation built by developers for developers. Get started in minutes, not hours.
- Effortless debugging.
- Get to the root of the issue fast with detailed event logs and error messages.
// Fetch and render streak UI
const streak = await trophy.users
.streak("user-123");
// Render streak component
return (
<StreakBadge
length={streak.length}
frequency={streak.frequency}
expires={streak.expires}
/>
); 
Gamification UI library
Pixel-perfect streaks UI components
Use our open-source gamification UI components as the foundation for your design system. Customize as you see fit. Designed to work perfectly with the Trophy API.
- One-command install
- Add any component to your project with a single CLI command. No extra dependencies to manage.
- Fully customizable
- Every component lives in your codebase. Tweak styles, layout, and behavior to match your brand.
- Open-source.
- MIT licensed and community-driven. Use in personal projects or production apps without restrictions.
Built for production workloads
Reliable infrastructure designed for performance at scale.
- Uptime SLA
- 99.99%
- p95 API Latency
- 200ms
- Monthly API Requests
- 150M
- Users Tracked
- 1M+
FAQ
Frequently asked questions
Have a different question and can’t find the answer you’re looking for? Send us an email.
Get started