The guide outlines the full process of adding a leaderboards feature to your web or mobile app using Trophy.
For illustration purposes we’ll use the example of a study platform that uses a daily leaderboard to create friendly competition around viewing flashcards.
Pre-requisites
- A Trophy account
- About 10 minutes
Trophy Setup
In Trophy, Metrics are the building blocks of gamification and model the different interactions users make with your product.
In this guide the interaction we’re interested in is flashcards-viewed, but you can create a metric that best represents the interaction you want to build leaderboards around.
In the Trophy dashboard, head to the metrics page and create a metric.
Once you’ve created your metric, head to the leaderboards page and create the leaderboards you want. You can find all the details on the types of leaderboards and the different use cases in the leaderboards docs.
For the purposes of this guide we’ve set up a daily leaderboard that tracks the total XP a user earns by viewing flashcards.
For a full guide on adding an XP feature to your web or mobile app, check out
our full guide.
In Trophy you track user interactions by sending Events from your code to Trophy APIs against a specific metric.
When events are recorded for a specific user, Trophy automatically updates their ranking in each leaderboard they are a part of.
This is what makes building gamified experiences with Trophy so easy, it does all the work for you behind the scenes.
Installing Trophy SDK
To interact with Trophy from your code you’ll use the Trophy SDK available in most major programming languages.
Install the Trophy SDK:
Next, grab your API key from the Trophy integration page and add this as a server-side only environment variable.
Make sure you don’t expose your API key in client-side code.
Tracking User Interactions
To track an event (user interaction) against your metric, use the metric change API.
The response to this API call is the complete set of changes to any features you’ve built with Trophy, including any changes to their ranking in any leaderboards they are a part of.
Validate this is working by checking the Trophy dashboard.
Displaying Leaderboards
You have a number of options for displaying leaderboards in your application. Here we’ll look at the most common options.
Pop-up Notifications
We can use the response of the metric change API to show pop-up notifications (or ‘toasts’) when users move up the rankings.
Here’s an example of this in action:
Leaderboard Rank Up Pop-up
Displaying Leaderboard Rankings
To fetch a leaderboard and its most up to date rankings, use the leaderboard API.
You can also use the run parameter with the date of the specific past ‘run’
of a leaderboard you want to fetch data for.
Here’s an example of the data returned from the leaderboard API:
Displaying User Rank History
Use the user leaderboard API to fetch data on how a specific user’s rank has changed over time in a particular leaderboard.
Here’s an example of the data returned from the user leaderboard rankings API which includes the users current rank in the rank attribute and an array of previous ranks in the history attribute:
Analytics
The leaderboards page in Trophy shows how many users are actively participating in a leaderboard, as well as a measure of competitiveness based on how many rank changes are occurring.
The analytics page also shows a distribution of users scores to help identify clusters of users within rankings.
Additionally the leaderboard rankings page shows current and past rankings of a leaderboard:
Get Support
Want to get in touch with the Trophy team? Reach out to us via email. We’re here to help!