Use when integrating the Lagged JavaScript SDK into an HTML5 game published on Lagged.com, adding Lagged leaderboards, handling Lagged ad placements, or setting up user authentication via the Lagged API. Initializes the Lagged SDK (window.LaggedAPI), retrieves player profile data, submits scores to native leaderboards, unlocks achievements, and integrates interstitial and rewarded ads for games on the Lagged.com game portal.
72
87%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
window.LaggedAPI is exposed after its loader script finishes. Initialization, player lookup, ads, leaderboards and achievements all hang off LaggedAPI.
Supported features: initialization handshake, player profile lookup, interstitial ads, rewarded ads, leaderboard score submission, and achievement unlocks.
lagged.js and wait for window.LaggedAPIsdk.init(devId, publisherId) with ids from the Lagged dashboardsdk.User.get; id > 0 means signed-in, id = 0 means guestsdk.Scores.save with the board id and final scoresdk.Achievements.save when criteria are metThe SDK URL is https://lagged.com/api/rev-share/lagged.js. Dynamically inject the script tag, then poll for window.LaggedAPI before proceeding.
const SDK_URL = 'https://lagged.com/api/rev-share/lagged.js'
async function loadLaggedSDK(timeoutMs = 10000) {
await new Promise((resolve, reject) => {
const s = Object.assign(document.createElement('script'), {
src: SDK_URL, async: true,
onload: resolve,
onerror: () => reject(new Error('Failed to load Lagged SDK'))
})
document.head.appendChild(s)
})
const started = Date.now()
while (typeof window.LaggedAPI === 'undefined') {
if (Date.now() - started > timeoutMs)
throw new Error('LaggedAPI did not appear within ' + timeoutMs + 'ms')
await new Promise(r => setTimeout(r, 50))
}
return window.LaggedAPI
}LaggedAPI.init requires both a developer id and a publisher id from the Lagged dashboard. Right after init, query the current player to read their id, name and avatar.
Wrap initLagged in a try/catch at the call site — on failure, disable leaderboard, achievement and ad calls so the game remains playable without SDK support.
async function initLagged(devId, publisherId) {
if (!devId || !publisherId) throw new Error('devId and publisherId are required')
const sdk = await loadLaggedSDK()
sdk.init(devId, publisherId)
const player = await new Promise((resolve) => {
sdk.User.get((response) => {
resolve((response && response.user) ? response.user : {})
})
})
// id > 0 = signed-in player; id = 0 = guest
const profile = {
isAuthorized: player.id > 0,
id: player.id || null,
name: player.name || null,
avatar: player.avatar || null,
}
console.debug('[Lagged] init complete', profile)
return { sdk, profile }
}Player data is read once during initialization via LaggedAPI.User.get(callback). The callback receives { user: { id, name, avatar } }. The full retrieval logic is demonstrated in the initLagged function above. If you need a guest fallback, generate a local id and persist it in localStorage.
LaggedAPI.APIAds.show(onClosed) displays an interstitial. Pause simulation and mute audio before the call; resume in onClosed.
function showInterstitial(sdk, { onOpened, onClosed } = {}) {
onOpened?.()
sdk.APIAds.show(() => {
onClosed?.()
})
}LaggedAPI.GEvents.reward(canShowReward, rewardSuccess) runs a two-phase rewarded ad:
canShowReward(success, showAdFn) — if success is true, call showAdFn() to display the ad; otherwise surface a fallback.rewardSuccess(success) — true means the player earned the reward; false means dismissed early or failed.function showRewarded(sdk, { onOpened, onRewarded, onClosed, onFailed } = {}) {
onOpened?.()
sdk.GEvents.reward(
(success, showAdFn) => {
if (success) showAdFn()
else onFailed?.('unavailable')
},
(success) => {
if (success) { onRewarded?.(); onClosed?.() }
else onFailed?.('not_completed')
}
)
}Each board is identified by a string id configured on the Lagged dashboard. There is no API to fetch entries or open a native popup.
function submitScore(sdk, boardId, score) {
return new Promise((resolve, reject) => {
sdk.Scores.save({ score, board: boardId }, (response) => {
if (response && response.success) resolve(response)
else reject((response && response.errormsg) || 'leaderboard_failed')
})
})
}LaggedAPI.Achievements.save(achievements, callback) unlocks one or many achievements in a single call. Display state is owned by Lagged — there is no list/get API.
function unlockAchievement(sdk, achievement) {
if (!achievement) return Promise.reject(new Error('achievement is required'))
return new Promise((resolve, reject) => {
const payload = Array.isArray(achievement) ? achievement : [achievement]
sdk.Achievements.save(payload, (response) => {
if (response && response.success) resolve(response)
else reject((response && response.errormsg) || 'achievement_failed')
})
})
}1adb800
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.