Configure gamification logic for your apps.
This package is currently in Beta. We recommend adding the version number
:0.1 to ensure the feature continues to work in your app if and when the package is upgraded.
Data models and key concepts
All user data is saved and accessed via a data source. The following sections describe the models that the game data use.
Logging looks at what the users are doing. When key actions and interactions occur, a log is generated in the data source. Here are some examples of what a log item could describe:
- A user has logged in
- A quiz has been completed
- A comment has been submitted
When a log entry is created or updated, the game engine triggers the computation of variables and achievements (see below).
Variables are used to define which aspects and statistics of the user we are interested in. These are used to keep track of the status of a user in the game at any given time. Here are some examples of what variables can be used to track:
- Number of points colected
- Number of articles read
- Amount of time spent watching videos
Variables are computed when a log entry is created or updated, or when a manual computation is triggered. When variables are computed, the game engine triggers the computation of achievements (see below).
Achievements are used to track specific milestones that users have reached. They are computed based on the user variables. Therefore, a computation is triggered when a user variable computation is completed. Here are some examples of what could constitute an achievement:
- User has read 10 articles
- User has submitted 5 questions
- User has watched 3 videos in a day
To start setting up gamification logic for your app, add
fliplet-like:0.1 to your app/page dependencies.
Users must be logged in to use game engine and store game data.
optionsRequired (Object) A map of options to pass to the constructor.
String) Data source ID or name in which game data will be stored.
passport(String) Passport type for accessing user data. Valid inputs are
saml2. Leave this undefined if the game engine is used without a login. Default:
primaryKey(String) Field name for the user data that would be used as the user’s key identifier. This is required if
computed(Object) A map of functions for computing variables and achievements.
userobject is passed to the function for computing the variables. Function must return an object or a Promise that resolves with an object containing the key-value pair values for the variables.
userobject is passed to the function for computing the achievements. Function must return an array or a Promise that resolves with an array containing a collection of achievement objects. Each achievement must contain an
idproperty that is unique to the achievement.
Fliplet.Gamify() function returns an object with the following methods.
Log data for the user.
The promise is resolved when the log operation is completed.
dataRequired (Object) Log data to be saved.
Attach a handler when an event is triggered.
eventNameRequired (String) Event name, such as
fnRequired (Function) A function to execute when the event is triggered.
Retrieves the user data containing logs, variables and achievements. Data is loaded from a cached response unless
forceUpdate is set to
true (see below).
The promise is resolved with the user object when the data is retrieved.
opt(Object) An optional map of options for the operation.
forceUpdate(Boolean) If set to
true, user data is loaded directly from the remote data source instead of from the cached data. Default:
Updates user data.
The promise is resolved when the update operation is completed.
dataRequired (Object) Data object containing the user attributes to be updated.
Resets user progress, including all logs, variables and achievements.
The promise is resolved when the reset operation is completed.
The following events are available for attaching using the
variablesTriggered when variables are computed. The handler is triggered with the new
newAchievementsTriggered when new achievements have been added for the user. The handler is triggered with an array of achievement objects with unique IDs.