Features6 / 12
Leaderboards
A leaderboard ranks players by a score built from the events your game already sends. Scores move as players play, with no batch job to wait for, and when the leaderboard ends you pay the winners by rank.
How a leaderboard scores
A leaderboard has scoring rules, the same rules live ops tracks use: which events earn points, and how many. Two settings say what the points do to a player's score.
| Setting | Options |
|---|---|
| Score | sum (default) adds up every rule's points. max keeps the most points one event gave: a high score. min keeps the fewest and ranks the lowest first: a best time |
| Tiebreaker | first-to-score (default) or last-to-score, for players on the same score |
To rank players by a number your game computes, such as a lap time, send it as a dynamic field and score it with a dynamicTracker rule in perAmount mode with 1 point.
A leaderboard also has a start and an end. Events score only between them. Either can be left open.
You build leaderboards on the Leaderboards page of the dashboard.
Kinds of leaderboard
| Kind | What it does |
|---|---|
| Single | One ranking, over one window |
| Repeating | Starts a fresh leaderboard every period: daily, weekly, any interval, or whenever you start the next one by hand. Your game keeps using one id, which always points at the current period |
| Sharded | Splits players into shards of a size you set. A player competes within their shard |
| Repeating and sharded | Every period has fresh shards |
Shards fill from buckets. A bucket is a set of conditions on the player, such as a level range or a country, and a player goes to the first bucket they match. So you can keep beginners with beginners. A player is placed in a shard on their first scoring event, or, if you choose, only when your game joins them.
Periods of a repeating leaderboard run on a schedule you set, or are started by hand: then a period runs until you press Start next period in the dashboard, or until the leaderboard's own end date. The period that ended can be paid at once.
Show a leaderboard
The JavaScript and Unity SDKs have leaderboard methods, and send the player's token for you. From anything else, call the API: the /v2/client/... paths with a player token from a game client, or the API-key paths from your backend.
With an SDK
// after the player signs in, and again whenever their rewards should be fresh: it loads
// the rewards the player can claim (see "Claim leaderboard rewards").
// The reads below prepare themselves if you skip it.
await client.initLeaderboards();
// the live leaderboards: prizes, the player's points and the first five ranks
const leaderboards = await client.listLeaderboards({ labels: { $in: ['weekly'] } });
// one leaderboard: every rank with what it is paid, and the player's own row
const standings = await client.getLeaderboard(leaderboards[0].id);
for (const row of standings.entries) {
console.log(row.rank, row.username ?? row.playerId, row.score, row.rewards);
}In Unity the same methods are InitLeaderboardsAsync, ListLeaderboardsAsync, GetLeaderboardAsync and JoinLeaderboardAsync, and for rewards ClaimableLeaderboardRewards, ClaimLeaderboardRewardAsync and ClaimAllLeaderboardRewardsAsync.
Every reward an SDK returns has the amount that would be paid: rounded down to the reward's unit, as it is when rewards are generated. Over HTTP the amounts are not rounded yet: see Amounts over HTTP. The fields below are the same either way.
List the game's leaderboards
POST/v2/client/leaderboards
With an empty body the answer has the leaderboards that are live now. Send any of these to narrow it, or to list others:
| Field | Meaning |
|---|---|
labels | { "$in": [...] } for the ones with any of these labels, { "$nin": [...] } for the ones with none of them, or both. Labels are compared exactly |
startDate, endDate | { "$gt": date, "$lt": date }, one bound or both: the ones that start (or end) after $gt and before $lt. A date is an ISO string or milliseconds. Sending either one replaces the live-only default |
targetId | Read as a linked entity of the player, such as a pet, as the standings do |
A leaderboard with no start counts as having always started, and one with no end as never ending. A field or operator the API does not know is refused with a 400, so a typo never returns the wrong list. From your backend, POST /v1/sdk/leaderboards takes the same fields, with playerId in place of targetId.
curl -X POST https://api.sandbox.stacked.xyz/v1/sdk/leaderboards \
-H "x-api-key: your_api_key" \
-H "x-client-id: your_client_id" \
-H "Content-Type: application/json" \
-d '{ "playerId": "player-1", "labels": { "$in": ["weekly"] }, "endDate": { "$gt": "2026-12-01T00:00:00Z" } }'Each one has id, name, description, labels, startDate, endDate, status (upcoming, live or ended), sharded, repeating, its scoring rules to show players how to score, and its prizes. The list has the game's leaderboards themselves, each with its own dates, which are the dates the filters look at. It never has a period of a repeating leaderboard or a shard of a sharded one: read the standings of a leaderboard (below) by its id to get the one that stands for it now, the current period and the player's shard. A repeating leaderboard is live while it repeats. At most 100 are listed, newest first.
Each one also has the player's points on it now: viewer is { playerId, username, score }, or null when they have none yet. The list does not have the player's rank: read the standings for that.
Each one comes with its first five ranks, to show the leaders without a call per leaderboard: top is [{ rank, playerId, username, score, rewards }], with the rewards that rank would be paid now (but for a share in proportion to points, which the standings have). A repeating leaderboard has its current period's, and a sharded one the shard of the player. It is empty for a sharded leaderboard when there is no player, or the player is in no shard yet, or their shard still waits for players (see the standings below). The rows can be a few seconds old. A leaderboard with a prize pool that grows has it as pool, as the standings do.
Read the standings
POST/v2/client/leaderboard
| Field | Meaning |
|---|---|
leaderboardId | The leaderboard's id |
page, limit | Which page, from 1, and how many rows: 100 by default, 200 at most |
repeater | Repeating only. 0 or absent is the current period, 1 the one before, 2 the one before that, -1 the next to come |
shardId | Sharded only. The id of the shard to read, when it is not the player's own |
global | Sharded only. true ranks the players of every shard together, instead of one shard: see one ranking across all shards |
curl -X POST https://api.sandbox.stacked.xyz/v1/player/leaderboard \
-H "x-api-key: your_api_key" \
-H "x-client-id: your_client_id" \
-H "Content-Type: application/json" \
-d '{ "leaderboardId": "68a1f3c2e4b0a1d2c3f4a5b6", "playerId": "player-1" }'The answer holds:
| Field | Holds |
|---|---|
leaderboard | The leaderboard the rows are from. For a repeating one that is a period, and templateId is the id that stays the same |
entries | The rows of this page: rank (1 is first), playerId, username, score, and the rewards that rank would be paid |
viewer | The player's own row, wherever they rank, or null when they have no score |
prizes | What each rank is paid, ready to draw: byRank (fromRank, toRank, rewards), byScore, byShare for rewards shared in proportion to points, and pools: the whole prize pool of each reward that shares one |
pool | Only with a prize pool that grows: count, rewards and rules |
repeat | Repeating only: repeater, hasPrevious, hasNext |
shard | Sharded only: the shard shown, with its id, its bucket, its number of players, and waiting while it waits for players |
global | true when the rows are a sharded leaderboard's ranking across all its shards |
total, page, limit, hasMore | Paging |
- A sharded leaderboard returns the player's own shard. To read another shard, send its
idasshardId, or as theleaderboardIditself. - A new shard waits for players. While a shard is new and has few players,
shard.waitingistrueandentriesis empty: show "waiting for more players", not a board of two. The player's own row (viewer) is still there. Waiting ends when the shard has 10 players, or is full if your shards are smaller, or has been open for 4 hours (or a sixth of the leaderboard's length, if that is shorter). It never waits once the leaderboard has ended. - Rows stop at the number of ranks you set for the leaderboard (1,000 by default). The player's own row is always returned.
- Every row has the player's name.
usernameis the name your game sent for that player with asign_in,sign_uporplayer_snapshotevent, and a new name shows within seconds. A player you sent no name for has nousername: showplayerId, your game's id for them. To search by name, filter the rows you have read.
One ranking across all shards
A sharded leaderboard normally shows a player their own shard. To show everyone together, ask for the standings with global: true:
const everyone = await client.getLeaderboard(leaderboard.id, { global: true });- The answer has
global: trueand noshard. Its ranks are across all shards. - It has the first ranks only: the number of ranks you set for the leaderboard (1,000 by default).
vieweris the player's own row when it is among them, andnullotherwise. Their points, and their rank in their shard, are on the standings withoutglobal. - Its rows have no
rewards: a sharded leaderboard pays by rank within each shard.prizesis still there, and says what each shard pays. - It is read from saved scores, so it can be up to 15 minutes behind a shard's own standings, which are live.
repeater,pageandlimitwork as for any standings. For a leaderboard that is not sharded,globalchanges nothing.
Amounts over HTTP
The API answers with amounts that are not rounded. When rewards are generated, each amount is rounded down to its reward's unit. To show what will be paid, round the same way (the SDKs do this for you):
POST /v2/client/leaderboards/init, orGET /v1/sdk/leaderboards/initfrom your backend, answerscurrencies:[{ kind, rewardId, name, roundDecimalPlaces }]. These are your game's currencies (coins) and the Stacked currencies (loyalty_currency). (The same answer has the player's rewards to claim, which are rounded already.)- Round a currency reward down to its
roundDecimalPlaces, and every other reward down to a whole number. Leave adiscountas it is. - A reward that rounds down to nothing is not paid: do not show it.
- In
prizes, a reward withpartsadds up several rewards of one currency. Round each part down, then add them.
A pool (prizes.pools, prizes.byShare, pool) is a figure to show, not a payout.
Join a leaderboard
Most leaderboards need no joining: a player is on the board as soon as they score. Joining matters for a sharded leaderboard that places players only on request.
POST/v2/client/leaderboard/join
Send leaderboardId. The answer has joined and, for a sharded leaderboard, the shard the player was given.
A leaderboard cannot be joined before it starts (leaderboard-not-started) or after it ends (leaderboard-ended). Join a player once the list shows it as live.
Rewards
Prizes come from reward templates, which belong to your game and can be attached to any number of leaderboards. A template pays:
- by rank: rank 1 gets this, ranks 4 to 10 get that;
- by score band: everyone above a score gets something;
- in proportion to points: every player with points gets a share of a prize pool, the pool × their points ÷ everyone's points;
- as fixed amounts, or as shares of a prize pool;
- with an optional boost for players who match conditions you set.
Nothing is paid automatically. When a leaderboard has ended, open its standings in the dashboard and press Generate rewards. For a repeating leaderboard, do it for each period. It can be done once.
When rewards are generated:
- Blacklisted players are left out, and everyone below them moves up a rank. So a rank's prize goes to the next player in line.
- On a sharded leaderboard every pool is split evenly over the shards. Each shard with players gets the same slice, and pays from it as a leaderboard without shards would: its ranks by their percents, its score bands among its own players, and a share in proportion to points by its own players' points. So rank 1 of a small shard wins as much as rank 1 of a big one, and a point is worth more in a small shard. A shard where nobody can be paid keeps its slice unpaid. A reward that only pays some buckets is split over those buckets' shards.
- Amounts are rounded down to the reward's unit: an in-game currency by the decimal places you set for it in the asset library, a Stacked currency by its own, and whole numbers when none is set and for items and everything else. An amount that rounds down to nothing pays nothing: there is no minimum, so a pool is never paid more than it holds.
A reward shared in proportion to points is shared by the leaderboard's players, or on a sharded leaderboard by the players of each shard, each shard sharing its slice. Only points above zero share, and it cannot be used on a leaderboard that ranks the lowest score first. Each share is rounded down to the reward's unit, and a player whose share rounds down to nothing gets nothing, so the pool is never paid more than it holds. Games see it in prizes.byShare, with the pool being shared: on a sharded leaderboard, one shard's slice. What one player would get is in their row's rewards only once the leaderboard has ended.
Generating grants nothing yet. Each winner's rewards are kept with their place on the leaderboard, waiting to be claimed. Nothing reaches your backend until a player claims theirs. A reward that is not claimed does not expire.
The dashboard's Payouts tab then shows where each winner's reward stands: waiting to be claimed, or claimed and when.
Claim leaderboard rewards
A player claims a leaderboard reward the way they claim any other: one claim, from your game client or from your backend.
With an SDK
// initLeaderboards() loaded them. Every call of it asks the server again, so call it
// when the player opens their leaderboards to pick up rewards generated since
const rewards = client.claimableLeaderboardRewards();
for (const reward of rewards) {
console.log(reward.name, `rank ${reward.rank}`, reward.rewards);
}
// claim one, or everything at once
await client.claimLeaderboardReward(rewards[0].id);
await client.claimAllLeaderboardRewards();A connected client is also sent new rewards the moment they are generated ("In realtime" below has the details):
import { OfferEvent } from '@pixels-online/pixels-client-js-sdk';
// claimableLeaderboardRewards() already has the new entry when this runs
client.events.on(OfferEvent.LEADERBOARD_ENTRY_UPDATED, ({ entry }) => {
if (entry.rewardsStatus === 'claimable') {
showRewardsBadge(client.claimableLeaderboardRewards().length);
}
});Over HTTP
POST /v2/client/leaderboards/init(player token) answersclaimableRewardsfor that player. From your backend,GET /v1/sdk/leaderboards/init?playerId=player-1does the same for the player you name.- Claim with
kind: "leaderboard"and the reward'sidas theinstanceId:POST /v1/client/reward/claimwith the player token, orPOST /v1/reward/sdk/claimwith your API key andplayerId.
Each item of claimableRewards is the player's entry on a leaderboard, with the rewards on it:
| Field | Meaning |
|---|---|
id | What to claim it with |
leaderboardId | The leaderboard it was won on. For a repeating leaderboard this is the period: read its standings by this id |
templateId | Only for a period: the repeating leaderboard, which is the id your list has |
shardId | Only on a sharded leaderboard: the shard the player was on |
name, description, startDate, endDate | The leaderboard's, or the period's |
playerId | Whose entry it is |
rank, score | The rank and the score the reward was won with. Rank 1 is first, within the player's shard on a sharded leaderboard |
rewards | What the claim grants: [{ kind, rewardId, name, amount, image }]. The amounts are final: they were rounded down when the rewards were generated |
rewardsStatus | claimable on every item of this list. It becomes claimed once the player claims |
rewardsGeneratedAt | When the rewards were generated |
The list has the newest first and at most 100. A player with more gets the rest as they claim.
In realtime
A game client that is connected is sent the entry the moment the leaderboard's rewards are generated: a leaderboard_entry_updated event whose data has the fields of an item above. The SDKs put it in the player's claimable rewards before your listener runs (OfferEvent.LEADERBOARD_ENTRY_UPDATED, OfferEvent.LeaderboardEntryUpdated in Unity), so the player can claim without another fetch.
- The event only reaches players who are connected right then: one who connects later never gets it. Keep calling
initLeaderboards()when the player signs in or opens their leaderboards. - The event is about the entry, not only about rewards, and may be sent for other changes of an entry later. Read
rewardsStatusbefore you treat one as a reward: it is absent on an entry that has none.
When a claim goes through, the player is granted the rewards once: Stacked currencies are credited, and your backend gets one user.gain_rewards reward webhook, the same one every other claim sends, with source: "leaderboard", the player's rank and score, the leaderboard's id as campaignId and the reward's id as instanceId. A claim that fails changes nothing, so it can be tried again.
| Error | Meaning |
|---|---|
leaderboard-reward-not-found | No reward with that id for this player |
already-claimed | It was claimed before |
player-blacklisted | The player is on your blacklist. A reward generated before you blacklisted them cannot be claimed while they are on it |
claim-failed | The rewards could not be granted. The usual cause: webhooks are not set up for this environment yet |
A prize pool that grows with play
A reward template that pays shares of a prize pool can have that pool grow as players play: "every coin spent adds 1 to the pot". You set it on the leaderboard's Rewards tab:
- What counts: scoring rules, like the ones that score the leaderboard. Every event that matches adds the rule's points to one count for the leaderboard, whoever the player is, on the board or not. A blacklisted player's events do not count.
- What the count is worth, for each reward template the pool pays:
| Curve | The pool is |
|---|---|
| Linear (default) | count × k, up to the limit |
| Exponential | limit × (1 − e^(−k × count)): it rises fast at first and nears the limit without passing it |
k is the curve's constant, 1 when you leave it empty. An exponential pool needs a limit.
Until something is counted, the template's own pool applies. A pool you set by hand on a leaderboard or a period always wins. Every period of a repeating leaderboard counts from zero. A sharded leaderboard has one count for all its shards, and the pool it comes to is split evenly over them like any other pool. pool shows what the whole count is worth.
A template the pool pays has one reward that shares a pool, with a percent on every rank and score band. To split one count over two rewards, use two templates, each with its own curve.
Games read it as pool in the standings and in the list:
| Field | Holds |
|---|---|
count | What has been counted so far |
rewards | One item per reward the pool pays: templateId, kind, rewardId, name, image, the pool's amount right now, and its limit when it has one |
rules | The rules that grow it, to tell players how: description, trigger, points, pointsMode, intervalMs |
prizes and each row's rewards already share the pool out, so a rank's prize grows with it. The numbers can be up to 15 seconds behind play.
Keep it fair
- Blacklist a player to stop their events from scoring on every leaderboard of your game, periods and shards included. The blacklist belongs to your game, not to one leaderboard. The score they already have is kept, but they are not shown: the standings, the list's
topand the player's ownviewerleave them out, everyone below them moves up a rank, and they are left out when rewards are generated. A reward that was generated for them before cannot be claimed while they are blacklisted. Taking them off the blacklist shows them again, and lets them claim. - Hide a leaderboard while you test it. It scores, but your game does not get it.
- Pause a leaderboard to stop it scoring.
- Points are fixed when they are earned. Changing a rule changes later events only, and scores are never worked out again from old events.