Connection and usage
Connection
Alert
To ensure your game passes moderation successfully, specify the up-to-date path for connecting Yandex Games SDK:
- If you upload the game archive to the Yandex server via the Developer Console, specify a relative path. This is the recommended option.
- If you are using integration via your own domain, specify an absolute path.
You can connect the Yandex Games SDK in two equally valid ways:
- Via the
<script>tag. - Dynamic loading — it allows you to programmatically control the connection process and handle loading events.
Yandex Server
Note
For proxying /sdk.js during development, use a local server. You don't have to download the sdk.js file.
Add the following line to the <head> section of your HTML page:
1<!-- Yandex Games SDK -->
2<script src="/sdk.js"></script>
Use the following attributes:
async— for non-blocking loading.onload— to execute code after the script loads.
Example code for running initSDK after the script loads. initSDK refers to SDK initialization:
1<!-- Yandex Games SDK -->
2<script async src="/sdk.js" onload="initSDK()"></script>
Add the following code snippet to your <script> tag or JSON file:
1const script = document.createElement('script');
2script.src = '/sdk.js';
3script.async = true;
4script.onload = initSDK;
5document.body.append(script);
In this example, initSDK refers to SDK initialization after the script loads.
Custom Domain
When hosting the game on your own domain, use the absolute path https://sdk.games.s3.yandex.net/sdk.js instead of the relative path /sdk.js:
1<!-- Yandex Games SDK -->
2<script src="https://sdk.games.s3.yandex.net/sdk.js"></script>
Usage
After the script loads, initialize the SDK using the init() method of the YaGames object.
Tip
The YaGames.init() and ysdk.getPayments() methods accept an optional signed: boolean parameter for fraud protection. The value depends on where payment processing occurs:
- Client-side processing — call methods without the
signed: booleanparameter or passsigned: false. Purchase methods will return data in plaintext. - Server-side processing — pass
signed: true. In this case, responses from payments.getPurchases() and payments.purchase() will return all data exclusively in encrypted form via the signature parameter.
Initialization with the default parameter (signed: false):
const ysdk = await YaGames.init();
Initialization with signed: true:
const ysdk = await YaGames.init({ signed: true });
Verification
Warning
The /sdk.js script must be connected before executing YaGames.init().
Check if the SDK is connected correctly using the loader:
-
Open the game with the debug panel:
Using the developer consoleUsing the address bar- Open the Yandex Games console.
- Select the game you need.
- In the top left corner, click on Open with debug panel.
-
Open the required game.
-
Add
&debug-mode=16to the end of the browser's address bar.Example link:
https://yandex.com/games/app/XXXX?debug-mode=16, whereXXXXis the unique game ID.
-
In the bottom left corner, check the value of the loader indicator:
W— waiting for initialization.IT— the SDK loader is initialized correctly.IF— an old loader is being used. Download the SDK according to the documentation.
Possible problems
Uncaught ReferenceError: YaGames is not defined
Pay attention to the order of integrating the sdk script: it must be integrated before YaGames.init() is run.
Uncaught ReferenceError: ysdk is not defined
You've tried to use SDK methods (ads, purchases, etc.) before initializing the SDK. You can track the initialization moment in debug mode by the Initialized message in the console. To control the order of calls, add SDK initialization before calling the method:
1const ysdk = await YaGames.init();
2
3ysdk.adv.showFullscreenAdv();
SDK connection example
1<!-- Yandex Games SDK -->
2<script async src="/sdk.js" onload="initSDK()"></script>
3<script>
4 async function initSDK() {
5 const ysdk = await YaGames.init();
6 ...
7 }
8</script>
Note
Our support team can help publish finished games on Yandex Games. If you have any questions about development or testing, ask them in the Discord channel.
If you are facing an issue or have a question regarding the use of Yandex Games SDK, please contact support: