Loading...
Loading...
Integrates the CrazyGames JavaScript SDK (v3) into a browser or HTML5 game. Handles SDK initialization, user authentication and profile retrieval, persistent key/value storage, interstitial and rewarded ad breaks, adblock detection, responsive banner ads, gameplay lifecycle hooks (loadingStart/Stop, gameplayStart/Stop, happytime), and optional Xsolla Pay Station in-app purchases with analytics order tracking. Use when the user mentions CrazyGames, wants to publish or integrate a game on CrazyGames, or needs to add SDK features like ads, user accounts, game events, storage, or in-game purchases to a browser/HTML5/JavaScript game.
npx skill4agent add hungify/playables-skills crazy-games-js-sdk<script>SDK.init()loadingStart/StopgameplayStart/Stop<script src="https://sdk.crazygames.com/crazygames-sdk-v3.js"></script>window.CrazyGames.SDK.initwindow.CrazyGamessdk.crazygames.comscript-srcSDK.init()SDK.userSDK.dataSDK.adSDK.bannerSDK.gameSDK.analyticsasync function initCrazyGames() {
if (!window.CrazyGames?.SDK) {
throw new Error('CrazyGames SDK script not loaded');
}
const sdk = window.CrazyGames.SDK;
try {
await sdk.init();
} catch (err) {
throw new Error(`CrazyGames SDK init failed: ${err.message}`);
}
const isUserAccountAvailable = sdk.user.isUserAccountAvailable;
if (isUserAccountAvailable) {
const language = sdk.user.systemInfo.countryCode.toLowerCase();
const deviceType = sdk.user.systemInfo.device.type.toLowerCase(); // 'desktop' | 'mobile' | 'tablet'
console.log('lang/device', language, deviceType);
}
return sdk;
}initCrazyGames()CrazyGames SDK init failedsdk.user.isUserAccountAvailableloadingStartloadingStopgameplayStartgameplayStop?crazygames_sandbox=1adStartedadFinishedsdk.ad.hasAdblock()trueshowAuthPrompt()getUser()getUserToken()async function authorizePlayer(sdk, { useUserToken = false } = {}) {
if (!sdk.user.isUserAccountAvailable) {
// Guest session — no auth possible on this domain
return null;
}
await sdk.user.showAuthPrompt();
const user = await sdk.user.getUser();
if (!user) {
return null;
}
const profile = {
name: user.username || null,
photo: user.profilePictureUrl || null,
extra: user
};
if (useUserToken) {
profile.extra.jwt = await sdk.user.getUserToken();
}
return profile;
}SDK.datafunction storageSet(sdk, key, value) {
const data = typeof value === 'string' ? value : JSON.stringify(value);
sdk.data.setItem(key, data);
}
function storageGet(sdk, key, tryParseJson = true) {
const raw = sdk.data.getItem(key);
if (!tryParseJson || raw == null) {
return raw;
}
try {
return JSON.parse(raw);
} catch (_) {
return raw;
}
}
function storageRemove(sdk, key) {
sdk.data.removeItem(key);
}
// Batch helpers — just iterate, the SDK has no native multi-key API
function storageSetMany(sdk, keys, values) {
for (let i = 0; i < keys.length; i++) {
storageSet(sdk, keys[i], values[i]);
}
}midgameSDK.ad.requestAd('midgame', callbacks)function showInterstitial(sdk) {
sdk.ad.requestAd('midgame', {
adStarted: () => {
// Mute audio and pause the game here
},
adFinished: () => {
// Resume audio and gameplay here
},
adError: (error) => {
console.warn('interstitial failed', error);
}
});
}'rewarded'adFinishedfunction showRewarded(sdk, onReward) {
sdk.ad.requestAd('rewarded', {
adStarted: () => {
// Pause the game
},
adFinished: () => {
onReward();
},
adError: (error) => {
console.warn('rewarded failed', error);
}
});
}async function isAdblockActive(sdk) {
return sdk.ad.hasAdblock();
}async function showBanner(sdk, containerId) {
// The container must already be in the DOM and visible
try {
await sdk.banner.requestResponsiveBanner([containerId]);
} catch (e) {
console.warn('banner failed', e);
}
}
async function showAdvancedBanners(sdk, containerIds) {
// Request several banners in parallel
await Promise.all(containerIds.map((id) => sdk.banner.requestResponsiveBanner(id)));
}
function hideBanners(sdk) {
sdk.banner.clearAllBanners();
}| Game event | SDK call |
|---|---|
| |
| |
| |
| |
| |
audiopausevisibilityadStartedadFinisheddocument.visibilitychangeSkip this section entirely if you do not have an Xsolla project ID. CrazyGames itself does not sell IAPs; this integration uses CrazyGames-issued Xsolla user tokens with the Xsolla Pay Station widget and Xsolla Store API.
const XSOLLA_PAYSTATION_EMBED_URL =
'https://cdn.xsolla.net/payments-bucket-prod/embed/1.5.0/widget.min.js';
const XSOLLA_SDK_URL = 'https://store.xsolla.com/api/v2/project';sdk.user.getXsollaUserToken()BearerGET /{projectId}/items?limit=50POST /{projectId}/payment/item/{sku}{ token, order_id }XSOLLA_PAYSTATION_EMBED_URLXPayStationWidget.init({ access_token: token, sandbox: isSandbox }).open()XPayStationWidget.eventTypes.STATUSpaymentInfo.status/done|charged|success/iGET /{projectId}/order/{orderId}sdk.analytics.trackOrder('xsolla', order)'close'GET /{projectId}/user/inventory/itemsPOST /{projectId}/user/inventory/item/consume{ sku, quantity }Authorization: Bearer <xsollaToken>isSandbox: true