Skip to main content

Setup and configuration

This section covers everything you need to get started with the JavaScript SDK, from obtaining your API credentials to initializing the SDK on your website.

Prerequisites

API key and site URL

To use the JavaScript SDK, you'll need:

  1. Widgets API Key - Found in the API Keys area of the administration panel
  2. Site URL - Found in the Sites area of the administration panel (the content of the URL column)

These credentials authenticate your website with the Mambo platform and determine which gamification site configuration to use.

Approved URLs

The most frequent troubleshooting issue with the JavaScript SDK is not configuring the allowed domains correctly. Access must be specifically granted to each domain/website that will use the SDK.

Define these URLs in the Approved URLs area of the API keys management page.

Note

The Approved URLs feature accepts the wildcard character (*) for matching subdomains and directory paths. This avoids having to define each individual URL. For example, to include all subdomains, use: _.domain.com/\*

Content Security Policy

The JavaScript widgets, along with required fonts and images, are loaded dynamically from Mambo's servers. To allow this, you must modify your site's Content Security Policy to include Mambo's servers as trusted sources.

Add https://versions.mambo.io to the following CSP fetch directives:

  • script-src
  • img-src
  • font-src

Example CSP header:

HTTP

Loading and initialisation

The following code should be placed directly after the <body> tag of your HTML page:

JavaScript

The mamboCallbacks array is also used to load widgets at any point on the page by adding functions to the array. For example, to load the Activities widget:

JavaScript
Note

Make sure Mambo.init() is the first function added to the mamboCallbacks array; otherwise, the SDK will not load properly.

Note

The userUuid parameter should be set to the unique identifier of the currently logged-in user. This UUID is set when you create the user.

On-premise installation

If you:

  • Cannot link to an external domain
  • Prefer to always use the latest widgets version, and
  • Have an on-premise Mambo licence

You can access a local copy of the latest version of the widgets:

  1. Copy the widgets folder from webapp/ROOT/docs/widgets to webapp/ROOT/static/widgets
  2. Before initializing the Mambo Widgets, set the Mambo.Static.versionRoot variable:
JavaScript

Initialisation options

The Mambo.init() function accepts numerous configuration options. Here's a complete example showing all available options:

JavaScript
Note

There should only be a single call to the Mambo.init() function on the page, and it must be the first function supplied to the mamboCallbacks array.

Options reference

OptionDescriptionRequiredDefault ValueSample Value
apiRootRoot URL where the API can be foundYesN/Ahttps://domain.com
keyJavaScript API Key from the API Keys panelYesN/A88342e5c41d748359a6
siteSite URL from the Sites panelYesN/Aacmeinc
userUuidUnique identifier for the current userYesN/A0001
langLanguage for the widgets (pt, en, or custom)Nopten
importFBWhether to load the Facebook SDK if not already presentNofalsetrue
fbAppIdFacebook App ID (required if importFB is true)NoN/A123456789900123
importTwitterWhether to load the Twitter Widgets SDKNofalsetrue
twitterViaTwitter handle to associate with shared tweetsNoN/Amambo_
socialUrlCustom URL for social sharing (overrides default site URL)NoN/Ahttp://mambo.io
profileUrlURL for the user's profile pageNonullhttp://domain.com/profile
themeColour theme for widgets (grey, blue, orange, yellow, red, green)Nobluegrey
rewardCounterWhether to display the number of times rewards have been unlockedNotruefalse
hideMissionRewardsControls visibility of rewards that are part of missionsNo{achievements: false, levels: false, gifts: false, missions: true}{achievements: true, levels: true, gifts: false, missions: true}
levelGroupsConfigures which levels should be used as primary levelsYesnull[{label:'Overall',tags:['primary'],isPrimary:true}]
levelGroups labelLabel for a group of related levelsYesnullOverall Experience Levels
levelGroups tagsTags to identify levels belonging to this groupYesnullmarketing
levelGroups isPrimaryWhether this is the primary level groupYesnulltrue
levelGroups noLabelsWhether to render levels as a single list without group labelsYesnulltrue
authentication redirectToLoginWhether to redirect to login page when authentication is requiredNotruefalse
authentication overrideLoginUrlCustom login page URLNonullhttps://mysite.com/my-login-page
authentication useCurrentPageAsRedirectUrlWhether to redirect back to current page after loginNotruefalse
authentication overrideRedirectUrlCustom redirect URL after successful loginNonullhttps://mysite.com/go-here
tags showWhether to display tags associated with rewardsNofalsetrue
tags withPersonalizationWhether to retrieve data with personalizationNofalsetrue
notifications withShowMoreWhether notification prizes should be hidden behind a Show More linkNotruefalse
notifications withActivitiesWhether notifications created by activities should include the activityNofalsetrue
notifications withPrizesOnlyWhether to only show notifications with prizesNotruefalse
notifications clearOnUnloadWhether to mark notifications as read when user leaves the pageNofalsetrue
notifications autoCloseTimeoutMilliseconds before notifications auto-close (null = never)Nonull5000
notifications positionPosition for notifications (bottomright, bottomleft, topright, topleft)Nobottomrighttopleft
debugWhether to output debug messages to the consoleNofalsetrue