The Rapidpace Gamification SDK adds a gamification button to your website. When a visitor clicks it, a panel opens with their gamification experience. The button's look and position come from your gamification settings in Rapidpace, so you only need to add the script once.
Installation
CDN Integration
Add this snippet to your website, before the closing </body> tag. Replace the placeholder values with your app's credentials.
<script>
(function (w, d) {
var urmGamificationSetting = {
appId: "your-app-id",
apiKey: "your-api-key",
};
function loadGamification() {
var s = d.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src =
"https://cdn.urm.app/js/gamification/RapidpaceGamification.js?date=" +
Date.now();
s.onload = function () {
w.urmGamification.initGamification(urmGamificationSetting);
};
d.head.appendChild(s);
}
if (d.readyState === "complete") {
loadGamification();
} else {
w.addEventListener("load", loadGamification);
}
})(window, document);
</script>Quick Start:
Once the script loads, the SDK is available as window.urmGamification. The button appears only if gamification is enabled for your app.
API Reference
Configuration Object
var urmGamificationSetting = {
appId: "your-app-id", // required
apiKey: "your-api-key", // required
profileId: "user-123", // optional
targetElementId: "game-root", // optional
};- appId (string, required): your Rapidpace app ID.
- apiKey (string, required): your Rapidpace API key.
- profileId (string, optional): the ID of the logged-in user. If you leave it out, the visitor is tracked with an anonymous ID.
- targetElementId (string, optional): the ID of the element to add the button to. Defaults to
document.body. The button stays fixed to the screen corner either way.
initGamification(settings)
Starts the SDK and shows the gamification button. The CDN snippet calls it for you.
Example:
window.urmGamification.initGamification({
appId: "your-app-id",
apiKey: "your-api-key",
profileId: "user-123",
});
Identify a logged-in user
If the user is already logged in when the page loads, pass their ID as profileId. Their points, levels and rewards are then linked to their account instead of an anonymous visitor.
var urmGamificationSetting = {
appId: "your-app-id",
apiKey: "your-api-key",
profileId: "user-123", // your user's ID
};
purge()
Clears the current visitor's session. Call it when a user logs out so the next person on the same device doesn't see their progress.
window.urmChat.purge();What happens?
- Rapidpace cookies are cleared.
- The profile ID is replaced with a new anonymous visitor ID.
- If a user was logged in, the gamification button reloads for the new anonymous visitor.
Button Appearance
You set the button's style in your gamification settings in Rapidpace. The SDK applies them automatically:
- Type: a round icon button, or a text tab on the side of the screen.
- Position: left or right, with configurable side and bottom spacing.
- Theme: separate light and dark colors. The SDK picks one based on the visitor's system color scheme.
The button has the ID gamification-button and a z-index of 1000. If it overlaps other elements on your page, you can raise its z-index with CSS:
#gamification-button {
z-index: 5000 !important;
}