Skip to main content

buildfire.gamify

This is a service that provides some reusable features that help gamify your app.

This service ties in with push notifications. It triggers notifications to users as the scoreboard changes. It creates an engaging competition among your users.

Requirements

Widget

Include scoreboard.js and pushNotifications.js file in widget header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../scripts/buildfire.min.js"></script>

<script src="../../../scripts/buildfire/services/gamify/scoreboard.min.js""></script>
<script src="../../../scripts/buildfire/services/notifications/pushNotifications.js"></script>
</head>

Control

Include scoreboard.js and pushNotifications.js file in control header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../../scripts/buildfire/services/gamify/scoreboard.min.js""></script>
<script src="../../../../scripts/buildfire/services/notifications/pushNotifications.js"></script>
</head>

Methods

constructor()

buildfire.gamify.Scoreboard(tagName, size, autoSubscribeToPushNotification)

This method will create a new scoreboard. Returns a scoreboard instance.

let scoreboard = new buildfire.gamify.Scoreboard("myScoreBoard", 20, true);

arguments

NameTypeRequiredDescriptionDefault
tagNamestringyesName of your scoreboard. Will be used to create publicData object to save the scoreboard in
sizenumberyesAn integer that limits the size of the scoreboard example top 10, top 25, top 100
autoSubscribeToPushNotificationbooleanyesDictates whether or not you want logged in users to automatically subscribe to the push notifications custom groupfor.

subscribe()

scoreboard.subscribe(callback)

This method will subscribe the current logged in user to the push notifications group

let scoreboard = new buildfire.gamify.Scoreboard("myScoreBoard", 20, true);

scoreboard.subscribe((err) => {
if (err) return console.log(err);

console.log("Subscribed to scoreboard.");
});

callback(err)

Callback function that is called upon the completion of the subscription.

NameTypeDescription
errstringerror string, null when operation is successful

unscubsribe()

scoreboard.unscubsribe(callback)

This method will unsubscribe the current logged in user to the push notifications group

let scoreboard = new buildfire.gamify.Scoreboard("myScoreBoard", 20, true);

scoreboard.unsubscribe((err) => {
if (err) return console.log(err);

console.log("Unsubscribed from scoreboard.");
});

callback(err)

Callback function that is called upon the completion of the unsubscription

NameTypeDescription
errstringerror string, null when operation is successful

logScore()

scoreboard.logScore(user, score, callback)

This method logs the user's score and will check to see if it qualifies to make it to the top of the list. If the user makes it to the top 3 on the scoreboard it will trigger corresponding push notifications. Also if you get knocked off the scoreboard you will get a push notification. It also increases the play count number.

let scoreboard = new buildfire.gamify.Scoreboard("myScoreBoard", 20, true);

buildfire.auth.getCurrentUser((err, user) => {
scoreboard.logScore(user, 50, (err, result) => {
if (err) return console.error(err);

console.log("Score logged", result);
});
});

user

Object representing the user you want to log the current score for.

NameTypeRequiredDescriptionDefault
userobjectyesObject representing the user you want to log the current score for.

score

Representing the user's score

NameTypeRequiredDescriptionDefault
scorenumberyesRepresenting the user's score

callback(err, result)

Callback function called after loging users score

NameTypeDescription
errstringerror string, null when operation is successful
resultobjectObject with the scoreboard data

result

NameTypeDescription
bumpedOffobjectIf user makes it to the scoreboard and bumps off someone from the list, that user record is returned as bumpedOff
rankedAtnumberIf user makes it to the scoreboard, returns users ranking

reset()

scoreboard.reset()

This method is used to reset the scoreboard

let scoreboard = new buildfire.gamify.Scoreboard("myScoreBoard", 20, true);

scoreboard.reset();

getScoreboard()

scoreboard.getScoreboard(callback)

This returns an object with the scoreboard data and number plays made

let scoreboard = new buildfire.gamify.Scoreboard("myScoreBoard", 20, true);

scoreboard.getScoreboard((err, scoreboard) => {
if (err) return console.error(err);

console.log("Scoreboard", scoreboard);
});

callback(err, scoreboard)

Callback function after getting the scoreboard

NameTypeDescription
errstringerror string, null when operation is successful
scoreboardobjectObject representing scoreboard

scoreboard

NameTypeDescription
gamesPlayednumberNumber of scores logged over time
topScores[object]Array of score record objects. records are sorted in the array by score

scoreboard.topScores

NameTypeDescription
userobjectUser object
scorenumberUsers score
createdOnDateTimestamp of when the record was created