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 infoconst player = await yes.getPlayer();console.log('Welcome, ' + player.username);// Submit a scoreconst result = await yes.submitScore(1000);if (result.isNewBest) {console.log('New high score!');}// Show a rewarded adconst 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
| Name | Type | Description |
|---|---|---|
score | number | The score to submit (must be a positive number) |
options? | object | Optional configuration object |
options.metadata? | object | Additional 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 submissionconst result = await yes.submitScore(1500);console.log('Your rank: #' + result.rank);if (result.isNewBest) {showCelebration('New Personal Best!');}// With metadataconst 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 failedif (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" buttonconst { 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 messagedocument.getElementById('welcome').textContent ='Welcome back, ' + player.username + '!';// Show player avatarif (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
| Name | Type | Description |
|---|---|---|
data | object | Plain object containing game state to save (max 10KB) |
Returns
Promise<SaveResult>Object containing success (boolean) and savedAt (ISO timestamp)
Example
// Save game progressconst 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 startupconst result = await yes.load();if (result.exists) {// Restore game stategame.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 gamegame.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 progressasync 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
| Name | Type | Description |
|---|---|---|
callback | function | Function to call when SDK is ready |
Example
// Wait for SDK before making callsyes.onReady(() => {console.log('SDK initialized!');// Now safe to call SDK methodsloadGame();});// Can register multiple callbacksyes.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 statelet player = null;let gameState = {score: 0,level: 1,coins: 0};// Initialize when SDK is readyyes.onReady(async () => {console.log('YES SDK v' + yes.version + ' initialized');// Get player infoplayer = await yes.getPlayer();document.getElementById('playerName').textContent = player.username;// Try to load saved progressconst saveResult = await yes.load();if (saveResult.exists) {gameState = saveResult.data;console.log('Loaded save from ' + saveResult.savedAt);}// Update UIupdateUI();// Check if ads are availableconst { ready } = await yes.isRewardedAdReady();document.getElementById('watchAdBtn').style.display = ready ? 'block' : 'none';});// Called when player completes a levelasync function onLevelComplete(levelScore) {gameState.score += levelScore;gameState.level++;// Submit score to leaderboardconst result = await yes.submitScore(gameState.score, {metadata: { level: gameState.level }});if (result.isNewBest) {showMessage('New High Score! Rank #' + result.rank);}// Auto-save progressawait yes.save(gameState);updateUI();}// Rewarded ad for extra coinsasync 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 gameasync 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 gameplayconsole.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 onlyconst saveData = {level: 5,coins: 1200,unlockedIds: [1, 2, 3]};// Bad - storing unnecessary dataconst saveData = {fullPlayerObject: {...}, // Don't duplicate player datagameAssets: [...], // Don't store assetsentireHistory: [...] // 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.