Skip to content

Setup Guide

This guide will show you how to setup the Client SDK for it to function within your web application.

Insert the following script in the site head tag

<script src="https://cdn.gamification.marshalldoes.dev/sdk.js"/>

Next is to setup the Client SDK with its configuration. This is best completed early in the startup flow of your site. The setup flow identifies this client as belonging to your site, and provides authentication to them.

window
.gamificationSaaS
.setup({
siteId: '',
auth: {
token: ''
}
})

A secure JSON Web Token is used to authenticate a user with our service. This gives your trusted backend a way to digitally sign a piece of data that confirms a user is who they say they are. We can then verify that your trusted environment has verified this users identity by checking for your signature on every request.

To create a JWT the following payload should be used

{
"sub": "<user id>",
"exp": 1475878357
}
  • UserId can be valid UTF-8 string.
  • We recommend setting an expiry of 1 day

Examples:

const jwt = require('jsonwebtoken');
function createToken(userId, secretKey) {
const payload = {
sub: userId
};
const options = {
expiresIn: '1d'
};
return jwt.sign(payload, secretKey, options);
}

Insecure Authentication is an alternate form of user authentication for purposes where a simple integration is desired. This removes the requirement for a backend to securely generate authentication tokens by allowing users to directly specify their user id.

window
.gamificationSaaS
.setup({
siteId: '',
auth: {
userId: ''
}
})