How to connect your game

Getting started with Connect for Web

Pointvoucher Connect provides a simple API for connecting your game to the Pointvoucher platform. You can prepare for this integration in three easy steps.

The script declares a global object PvConnect that you can initialize with your game details and a callback function.

PointvoucherCDN:

Copy-paste this code inside the head section of your website’s HTML or as close to the top of the page as possible.

Production CDN:

<!-- Latest compiled and minified JavaScript -->
<script src="https://sdk-prod.pointvoucher.com/pointvoucher-connect.js" crossorigin="anonymous"></script>

Development CDN:

<!-- Latest compiled and minified JavaScript -->
<script src="https://sdk-dev.pointvoucher.com/pointvoucher-connect-dev.js" crossorigin="anonymous"></script>

Demo (readme) page:

https://sdk-dev.pointvoucher.com

Usage:

function myinit() {

  // log any errors
  PvConnect.onError(e => console.error(e.message));

  // initialize Connect
  PvConnect.init({
    api_key: "eyJhbGciOiJIUzI1Ni..."
  }, () => {

  // call a method
  PvConnect.getUserData((data) => {
    console.log("The user's data %o", data)
  });
})}

Once initialized, you can at any time invoke the action method to trigger a user facing notification message. The method takes a context string and an optional callback as arguments. CONTEXT_TITLE_SCREEN may for example trigger a notification that invites the user to join Pointvoucher.

action method is not supported yet!

PvConnect.action(PvConnect.CONTEXT_TITLE_SCREEN, () => {
  console.log(`Let's play!`);
});
PvConnect.getUserData((data) => {
  console.log("The user's data %o", data)
});

If provided, the callback gets invoked as soon as the data is ready, or when the user is done interacting with Connect, for example when the user swipes the invitation away or when the signup process has been completed. The SDK may also decide, not to show a notification at this point in time, in which case the callback gets invoked immediately. Connect adapts its behavior to the following contexts.

CONTEXT_TITLE_SCREEN
Used before the user presses Play. A notification may advertise the integration with Pointvoucher and invite the user to sign up.
CONTEXT_LEVEL_COMPLETE
Used in between game levels or some equivalent break in active gameplay. A notification may display points earned.
CONTEXT_GAME_OVER
When the game ends, a notification may display points earned.

Remember that Connect may always decide, not to show a notification when the action method is called, for example when the user has accumulated zero voucher points since the last status update.

Pointvoucher supports all the latest browsers, but notably not Safari 10 or any version of Microsoft Edge released before 2020. The SDK itself will not throw exceptions in unsupported browsers. Instead, it will simply never display notifications and always execute your callback functions immediately. The Pointvoucher integration is in other words invisible to users of legacy browsers.

Firefox
Chrome
Edge 79+
Safari 12.1+

PvConnect

MethodParamsReturnsDescription
action
  • string context
  • Function callback
void

Instruct Connect to display an appropriate notification based on the given context. The optional callback is invoked when the notification gets dismissed or closes automatically.

init
  • Object config
  • Function callback
void

Initialize Connect whenever the user opens the game. The optional callback is invoked when initialization either succeeded or failed. Make sure to configure method onError to identify the cause of potential failure.

onError
  • Function callback
void

Get an angle on potential errors since Connect is otherwise designed to fail silently. The callback receives an object with a message property.

openAccount
  • Function callback
void

Open the user's account page via Pointvouchers website. The optional callback is invoked when the popup is closed or when a user goes to a different page.

openShop
  • Function callback
void

Open the voucher shop via Pointvouchers website. The optional callback is invoked when the popup is closed or when a user goes to a different page.

openWelcome
  • Function callback
void

Open the welcome page via Pointvouchers website. The optional callback is invoked when the popup is closed or when a user goes to a different page.

onModalClose
  • Function callback
void

Subscribe to when the user closes the Pointvoucher modal.

startPings
  • void
void

Start collecting points for a user until the maximum number of points is reached (you can subscribe to this event using onMaxRatioReached)

endPings
  • void
void

Stop collecting user points.

harvestPoints
  • void
void

Harvest currently collected points.

onPointsRatioUpdate
  • Function callback
number

Subscribe to user collecting points. The callback will receive current points ratio (0 to 1).

onMaxRatioReached
  • Function callback
void

Subscribe to when the user collects maximum number of points, harvest them in order to keep collecting.

getUserData
  • Function callback
Object

Fetch information about the user.

getRecentRewards
  • Function callback
Object

Fetch recent rewards information.

getDailyRewards
  • Function callback
Object

Fetch daily rewards information. Only available to registered users (getUserData(data) data.anonymous === false)

getDailyPointsLimit
  • Function callback
number

Fetch daily points limit information.

showNotification
  • String type
void

Displays notification of a specific type. Still in development. Available types: LIMIT_REACHED, CLAIM_REWARDS, LOSE_STATE, WIN_STATE_PLAYING, WIN_STATE_CLAIM, HARVEST_POINTS, WELCOME_DAILY, PREMIUM