Is there a way to show a user's rank as a percentage?

I want to show the user’s current rank as a percentage with the formula (user’s current rank/all users). Are there APIs that will make this possible?

Hi DragonGalaxy,

thanks for looking into leaderboards! There is currently no single API for that exact information but the following two calls should do the trick:

  • First retrieving a page of scores via the GetScoresAsync method in the SDK or else from the API directly (docs can be found here) will provide the total number of scores (aka the number of users in the leaderboard) as a field on the return object
  • Then fetching the user’s current rank via GetPlayerScoreAsync in the SDK or the API (docs)

That would provide the inputs for the percentage formula. If you roughly know where the user currently is on the leaderboard, you might be able to use the limit and offset parameters on the first call to include the user in the returned page and skip the second call.

Alternatively if the percentage does not need to be exact, you could use percentage-based tiers. For example by creating tiers in 5 or 10% intervals, and then the appropriate tier label will be returned along with the rank when the user score is fetched.

Hope this helps, and let me know if there are any other questions :slight_smile:

2 Likes

GetScores method has a maximum limit of 1000. what if there are 100,000 users recorded on the leaderboard? Is there any way to know the number of users recorded on the leaderboard?

Hi DragonGalaxy,

there is actually no need to fetch all the scores since the GetScores response object includes a dedicated total field which provides the total number of scores on the leaderboard. Fetching a single score by specifying the ?limit=1 query parameter would be enough to provide that information.

1 Like