API Examples

Link to the api from the index
<script type="text/javascript" src="https://lagged.com/api/rev-share/lagged.js"></script>
Call the init after everything loads, before anyother API calls
LaggedAPI.init('YOU_DEV_ID', 'YOUR_PUBLISHER_ID');

Ads *required

Call ads on button clicks (Play buttons, next level, etc). Pause game and music while ad is playing
//
//pause game / music before calling:
//
LaggedAPI.APIAds.show(function() {

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

console.log("ad completed");

});

Reward Ads *optional

Increase Revenue:
Games using reward ads earn 3x more on average. Give users rewards (extra life, puzzle hints, etc) for watching an ad.
Two steps: Check if ad available, if it is then show user a button to click
  //step 1: call this to check if reward ad available
  LaggedAPI.GEvents.reward(canShowReward,rewardSuccess);
  //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
    }
  }
  //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();
  }
While uploading a new game you can add Highscore and Achievements. You will recieve IDs there.

Achievements

To call an achievement, just replace AWARD_ID with the correct id (see below)
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);
}
});

Award IDS:

Example Achievement
example_awardid_j001

High Scores

To call a high score just replace SCORE_VAR (integer) and HS_BOARD_ID (string, see below).
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);
}
});

Board IDs:

example_boardid_jf01