YES SDK

Integrate your games with the YES platform. Add leaderboards, player data, rewarded ads, and save/load functionality with just a few lines of code.

1Getting Started

No installation needed

The SDK is automatically injected into your game when it runs on the YES platform. Just use the global yes object.

Quick Start

// Get player info
const player = await yes.getPlayer();
console.log('Welcome, ' + player.username);
// Submit a score
const result = await yes.submitScore(1000);
if (result.isNewBest) {
console.log('New high score!');
}
// Show a rewarded ad
const ad = await yes.showRewardedAd();
if (ad.rewarded) {
givePlayerCoins(100);
}

Local Development

When running outside the YES platform (e.g., local development), the SDK operates in standalone mode and returns mock data. This allows you to develop and test without being connected to the platform.

2API Reference

Scores

Boost Player Retention

Leaderboards drive competition and keep players coming back. Games with score systems see significantly higher retention rates as players compete to climb the ranks.

yes.submitScore()#

yes.submitScore(score: number, options?: SubmitScoreOptions): Promise<SubmitScoreResult>

Submit a score to the leaderboard for the current game. The score will be associated with the current player.

Parameters
NameTypeDescription
scorenumberThe score to submit (must be a positive number)
options?objectOptional configuration object
options.metadata?objectAdditional data to store with the score (e.g., level, time)
Returns

Promise<SubmitScoreResult>Object containing isNewBest (boolean), rank (number), and score (number)

Example
// Simple score submission
const result = await yes.submitScore(1500);
console.log('Your rank: #' + result.rank);
if (result.isNewBest) {
showCelebration('New Personal Best!');
}
// With metadata
const result = await yes.submitScore(2500, {
metadata: {
level: 5,
timeSpent: 120,
difficulty: 'hard'
}
});

Ads

yes.showRewardedAd()#

yes.showRewardedAd(): Promise<RewardedAdResult>

Display a rewarded video ad to the player. The player can earn rewards by watching the full ad.

Returns

Promise<RewardedAdResult>Object containing rewarded (boolean), and optionally errorCode and errorMessage if failed

Example
const result = await yes.showRewardedAd();
if (result.rewarded) {
// Player completed the ad - give reward!
player.coins += 100;
showMessage('You earned 100 coins!');
} else {
// Ad was skipped or failed
if (result.errorCode === 'USER_DISMISSED') {
showMessage('Watch the full ad to earn rewards');
} else if (result.errorCode === 'NOT_LOADED') {
showMessage('No ad available right now');
}
}

yes.isRewardedAdReady()#

yes.isRewardedAdReady(): Promise<AdReadyStatus>

Check if a rewarded ad is available to show. Use this to conditionally display 'Watch Ad' buttons.

Returns

Promise<AdReadyStatus>Object containing ready (boolean)

Example
// Check before showing the "Watch Ad" button
const { ready } = await yes.isRewardedAdReady();
const watchAdButton = document.getElementById('watchAdBtn');
watchAdButton.style.display = ready ? 'block' : 'none';

Player

yes.getPlayer()#

yes.getPlayer(): Promise<Player>

Get information about the current player. Returns the player's ID, username, and avatar URL.

Returns

Promise<Player>Object containing id (string), username (string), and optional avatarUrl (string)

Example
const player = await yes.getPlayer();
// Display welcome message
document.getElementById('welcome').textContent =
'Welcome back, ' + player.username + '!';
// Show player avatar
if (player.avatarUrl) {
document.getElementById('avatar').src = player.avatarUrl;
}

Save/Load

Size Limit

Save data is limited to 10KB when serialized. Keep your save data minimal and avoid storing large assets.

yes.save()#

yes.save(data: object): Promise<SaveResult>

Save game progress for the current player. Data is persisted to the player's account and available across sessions.

Parameters
NameTypeDescription
dataobjectPlain object containing game state to save (max 10KB)
Returns

Promise<SaveResult>Object containing success (boolean) and savedAt (ISO timestamp)

Example
// Save game progress
const saveData = {
level: 5,
coins: 1200,
unlockedItems: ['sword', 'shield'],
settings: {
soundEnabled: true,
difficulty: 'medium'
}
};
try {
const result = await yes.save(saveData);
console.log('Game saved at: ' + result.savedAt);
} catch (error) {
console.error('Save failed:', error.message);
}

yes.load()#

yes.load(): Promise<LoadResult>

Load previously saved game progress for the current player. Returns null if no save exists.

Returns

Promise<LoadResult>Object containing exists (boolean), data (object or null), and savedAt (ISO timestamp if exists)

Example
// Load saved game on startup
const result = await yes.load();
if (result.exists) {
// Restore game state
game.level = result.data.level;
game.coins = result.data.coins;
game.unlockedItems = result.data.unlockedItems;
console.log('Loaded save from: ' + result.savedAt);
} else {
// No save found - start new game
game.startNewGame();
}

yes.deleteSave()#

yes.deleteSave(): Promise<DeleteSaveResult>

Delete the saved game progress for the current player. Use this for 'New Game' functionality.

Returns

Promise<DeleteSaveResult>Object containing success (boolean)

Example
// Reset game progress
async function startNewGame() {
await yes.deleteSave();
game.reset();
showMessage('Starting fresh!');
}

Lifecycle

yes.onReady()#

yes.onReady(callback: () => void): void

Register a callback to execute when the SDK is fully initialized. Safe to make API calls inside the callback.

Parameters
NameTypeDescription
callbackfunctionFunction to call when SDK is ready
Example
// Wait for SDK before making calls
yes.onReady(() => {
console.log('SDK initialized!');
// Now safe to call SDK methods
loadGame();
});
// Can register multiple callbacks
yes.onReady(() => {
initializeAnalytics();
});

yes.version

Read-only property that returns the current SDK version string.

console.log(yes.version); // "1.0.0"

3Full Example

Here's a complete example showing how to integrate all SDK features in a game:

game.js
// Game state
let player = null;
let gameState = {
score: 0,
level: 1,
coins: 0
};
// Initialize when SDK is ready
yes.onReady(async () => {
console.log('YES SDK v' + yes.version + ' initialized');
// Get player info
player = await yes.getPlayer();
document.getElementById('playerName').textContent = player.username;
// Try to load saved progress
const saveResult = await yes.load();
if (saveResult.exists) {
gameState = saveResult.data;
console.log('Loaded save from ' + saveResult.savedAt);
}
// Update UI
updateUI();
// Check if ads are available
const { ready } = await yes.isRewardedAdReady();
document.getElementById('watchAdBtn').style.display = ready ? 'block' : 'none';
});
// Called when player completes a level
async function onLevelComplete(levelScore) {
gameState.score += levelScore;
gameState.level++;
// Submit score to leaderboard
const result = await yes.submitScore(gameState.score, {
metadata: { level: gameState.level }
});
if (result.isNewBest) {
showMessage('New High Score! Rank #' + result.rank);
}
// Auto-save progress
await yes.save(gameState);
updateUI();
}
// Rewarded ad for extra coins
async function watchAdForCoins() {
const result = await yes.showRewardedAd();
if (result.rewarded) {
gameState.coins += 100;
await yes.save(gameState);
showMessage('You earned 100 coins!');
updateUI();
}
}
// Start new game
async function newGame() {
await yes.deleteSave();
gameState = { score: 0, level: 1, coins: 0 };
updateUI();
}

4Best Practices

Error Handling

All async methods return Promises. Always handle errors gracefully:

try {
const result = await yes.submitScore(1000);
// Success
} catch (error) {
// Show user-friendly message, don't block gameplay
console.error('Score submission failed:', error.message);
}

Score Submission Timing

Submit scores at natural game moments - end of level, game over, or achievement completion. Avoid spamming score submissions during gameplay.

Save Data Size

Keep save data under 10KB. Store only essential game state:

// Good - essential data only
const saveData = {
level: 5,
coins: 1200,
unlockedIds: [1, 2, 3]
};
// Bad - storing unnecessary data
const saveData = {
fullPlayerObject: {...}, // Don't duplicate player data
gameAssets: [...], // Don't store assets
entireHistory: [...] // Keep history minimal
};

Testing Locally

The SDK returns mock data in standalone mode, so you can develop and test without uploading to YES. All API calls will succeed with sample responses.