SDK Examples and Plugins

Create Your Account

Create your account now before using our SDK.

Add the .js file to your index.html page

<script type="text/javascript" src="https://lagged.com/api/rev-share/lagged.js"></script>

Call init() after everything loads. Use onload="" on the script tag above for best performance.

LaggedAPI.init('YOU_DEV_ID', 'YOUR_PUBLISHER_ID');

Interstitial Ads *required

Call ads during natural game breaks (Before level, after level, etc). Pause game and music while ad is playing. SDK handles Ad cooldown. In dev mode ads will show each time for testing.

//
//pause game / music before calling:
//
LaggedAPI.APIAds.show(function() {

  //
  // ad is finished, unpause game/music
  //

console.log("ad completed");

});

Reward Ads *recommended

Increase Revenue

Games using reward ads earn 3x more on average. Give users rewards (extra life, puzzle hints, etc) for watching an ad.

Reward ads work in two steps: First check if ad available (hide buttons before reward is available). Once an ad is available then you can give user an option to accept reward (show button). You can call this mutliple times until a reward ad is avaialbe.

//step 1: call this to check if reward ad available
LaggedAPI.GEvents.reward(canShowReward,rewardSuccess);

Make sure to show your reward button if ad is available, and attach the showAdFn(); function to the button

//this will be called if a reward ad can be shown or not
  var canShowReward=function(success,showAdFn){
    if(success){

      //you can show user a button for a reward, must call showAdFn() on click
      //ex: rewardButton.onclick=function(){showAdFn();}

    }else{
      //no ad to show, do nothing
    }
  }

Check if the reward is a success or failure

//after ad is played (after showAdFn() is called)
  var rewardSuccess=function(success){
    if(success){
      //give user the reward
    }else{
      //no reward
    }

    //remove reward button
    //ex: rewardButton.remove();
  }

Increase Engagement & Visibility

You can add Achievements and High scores while uploading your game. These features increase game plays, revenue and visibility on Lagged.

Achievements

To call an achievement, just replace AWARD_ID with the correct id. Award_IDs are generated when uploading your game

var api_awards=[];
api_awards.push(AWARD_ID);
//can push more than one award at a time
LaggedAPI.Achievements.save(api_awards, function(response) {
if(response.success) {
console.log('achievement saved')
}else {
console.log(response.errormsg);
}
});

High Scores

To call a high score just replace SCORE_VAR (integer) and HS_BOARD_ID. Board_IDs are generated when uploading your game

var boardinfo={};
boardinfo.score=SCORE_VAR;
boardinfo.board=HS_BOARD_ID;
LaggedAPI.Scores.save(boardinfo, function(response) {
if(response.success) {
console.log('high score saved')
}else {
console.log(response.errormsg);
}
});

User Information

You can get user infomation (username, ID and avatar). Registered users will have an ID > 0

LaggedAPI.User.get(function(userData) {
console.log(userData);
console.log(userData.user.id);
console.log(userData.user.name);
console.log(userData.user.avatar);
});