Javascript Library Integration

Project presentation

Introduction

The library described in this document aims to broadcast messages of advertisers. These are native ads dedicated for video games and totally integrated in the game experience.

Our format of native advertising is based on four key values:

  • It respects the game graphics
  • It appears in a positive moment of achievement for the player
  • It congratulates and rewards the player with a non-incentivized content of the game (item, currency, bonus…)
  • It offers to the player the possibility to click on a link or a button. The click is optional, there is no incentive to force the interaction.

The design of the window is achieved by the Playtem team, based on graphical elements provided by the game publisher.

Integration in the game

The library integration is extremely simple. There are three steps:

  1. Include the library in your project.
  2. Create a new Playtem client and initialize it.
  3. Retrieve an ad.

1) Include the library in your project

Insert this tag in the <head> section of your file:

<script type="text/javascript" src="https://sdk.playtem.com/web/sdk.js"></script>

2) Create and initialize a new client

Call the function Playtem.Init() with your parameters. Here is an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
Playtem.init({
    apiKey: "API_KEY",
    userId: "USER_ID",
    onAdAvailable: function() {
        console.log("Page.onAdAvailable");
    },
    onAdClick: function() {
        console.log("Page.onAdClick");
    },
    onAdClosed: function() {
        console.log("Page.onAdClosed");
    },
    onAdUnavailable: function() {
        console.log("Page.onAdUnavailable");
    },
    onCreditReward: function(userId, rewardId) {
        console.log("Page.onCreditReward(userId = %s, rewardId = %s)", userId, rewardId);
    }
});

Playtem.GetAdvert();
Parameters Description
apiKey: string

Mandatory. Your game’s Api Key at Playtem. This key is communicated by our technical team.

Example Values: “fad0a2434a8b7bbab994241ae1317099”

userId: string

Mandatory. The id of the player who made the call. Use your own ids.

Example Values: “ABcd948”

onAdAvailable: function Optional. A callback function fired when the ad has been loaded.
onAdClick: function Optional. A callback function fired when the player has accomplished the action (click on a link, like a facebook fan page …)
onAdUnavailable: function Optional. A callback function fired when the ad could not be loaded.
onAdClosed: function Optional. A callback function fired when the player closes the ad window.
onCreditReward: function Optional. Only for clients that want to reward their users themselves.

3) Retrieve an ad from Playtem server

Call the function Playtem.GetAdvert(); This will retrieve and display an ad on the center of the screen of the player.

1
Playtem.GetAdvert();