Learn how to use Trophy to add an XP feature to your web or mobile app.
The guide outlines the full process of adding an XP feature to your web or mobile app using Trophy.For illustration purposes we’ll use the example of a study platform that uses XP to reward users for taking different interactions.
To see a fully working example of this in practice, check out the live
demo or github
repo.
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 any number of metrics that best represents the interactions you want to reward XP from.In the Trophy dashboard, head to the metrics page and create a metric.
Once you’ve created your metric, head to the points page and create a new points system called ‘XP’.
Once created, you’ll be taken to the configure page for the XP system where you can create ‘triggers’ for each of the ways you want to reward users with XP.
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 will automatically check if the event is against a metric that is configured as part of any XP triggers.If so Trophy will award the user with the appropriate amount of XP according to the trigger configuration.This is what makes building gamified experiences with Trophy so easy, it does all the work for you behind the scenes.
XP can also be awarded to users based on achievements, streaks and other
triggers. See the dedicated points docs
for more information.
The response to this API call is the complete set of changes to any features you’ve built with Trophy, including any XP that was awarded to the user as a result of the event, and from what triggers it was awarded.
We can use the response of the metric change API to show users pop-up notifications when users are awarded new XP.Here’s an example of this in action:
XP Pop-ups
Copy
Ask AI
// Sends event to Trophyconst response = await viewFlashcard();if (!response) { return;}const xp = response.points.xp;// Show toast if user was awarded XPif (xp.awards.length > 0) { const trigger = xp.awards[0].trigger; toast({ title: `You gained ${xp.added} XP`, // e.g. "+20 XP for 10 flashcards flipped" description: `+${trigger.points} XP for ${ trigger.metricThreshold } ${trigger.metricName.toLowercase()}`, });}
If you want to play sound effects, use the HTML5 Audio
API and feel
free to steal these audio
files
we recommend.
curl --request GET \ --url https://api.trophy.so/v1/users/{id}/points/{key} \ --header 'X-API-KEY: <api-key>'
This API returns data on the user’s total XP but can be configured to also return between 1 and 100 of the user’s most recent XP awards by using the awardsquery parameter.
In Trophy your xp system page, includes analytics charts that shows data on total XP earned and a breakdown of exactly what triggers award the most XP.