The guide outlines the full process of adding a streaks 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 streak to incentivize and reward users for 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 drive streaks from.
In the Trophy dashboard, head to the metrics page and create a metric.
Once you’ve created your metric, head to the streaks page and select the streak frequency you want (daily, weekly or monthly).
Then add your metric to the streak conditions and set the threshold users must meet (e.g. at least 1 to extend their streak each period).
You can also add multiple metrics and choose whether users must meet all of them or just one—see the streak conditions docs for details.
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 whether they’ve met their streak conditions for the current period and update the user’s streak accordingly.
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.
By including the user’s timezone in the tz attribute, Trophy will
automatically track streaks according to the user’s local clock and handle
awkward edge cases where users change time zones.
The response to this API call is the complete set of changes to any features you’ve built with Trophy, including the latest data on the users streak.
Validate this is working by checking the Trophy dashboard.
Displaying Streaks
You have a number of options for displaying streaks 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 user extends their streak.
Here’s an example of this in action:
Displaying User Streaks
To fetch data on a user’s streak use the user streak API.
This API not only returns data on the user’s current streak like length and expires, but it can also return historical streak data which can be used to display any kind of streak UI you like through the historyPeriods parameter.
Here’s an example of a git-style streak calendar built using the data in the response above:
Check this example
repo
for a React component that drives this UI using data from Trophy.
Analytics
The streaks page in Trophy shows data on active streaks, the average length of streaks and longest streaks.
Streak Freezes
Trophy also supports streak freezes which can help prevent users from losing their streak if they accidentally miss a period.
Learn more about streak freezes in the dedicated streak freezes docs.
Get Support
Want to get in touch with the Trophy team? Reach out to us via email. We’re here to help!