SDK installation and use

The Yandex Games SDK is a library that you can use to easily integrate games created by third-party developers into the Yandex Games platform.

Connecting the SDK is a prerequisite for successful moderation.

With SDK, you can:

  • Integrate ad serving.
  • Enable and disable features without updating the build.
  • Set up automatic transition to the full-screen mode.
  • Set the screen orientation during the game and add a prompt for the user to turn their device.

Installation

You can connect the Yandex Games SDK either synchronously or asynchronously. Both options are equally valid, but the asynchronous connection enables you to control the installation process via callbacks. Choose the method you find most appropriate.

Add the following line to the head of your HTML page:

<!-- Yandex Games SDK -->
<script src="/sdk.js"></script>

With this method, you can use the async, defer, and onload attributes for the script. For example:

<script async src="/sdk.js" onload="initSDK()"></script>

Add the following code to your HTML page:

<!-- Yandex Games SDK -->
<script>
    (function(d) {
        var s = d.createElement('script');
        s.src = '/sdk.js';
        s.async = true;
        s.onload = initSDK;
        d.body.append(s);
    })(document);
</script>

For proxying /sdk.js during development, use a local server.

Connecting on Your Own Domain

Pass the following line to the head of the HTML page:

<!-- Yandex Games SDK -->
<script src="https://sdk.games.s3.yandex.net/sdk.js"></script>

Add the following code to the HTML page:

<!-- Yandex Games SDK -->
<script>
    (function(d) {
        var s = d.createElement('script');
        s.src = "https://sdk.games.s3.yandex.net/sdk.js";
        s.async = true;
        s.onload = initSDK;
        d.body.append(s);
    })(document);
</script>

Initialization

To get started, initialize the SDK using the init() method of the YaGames object.

YaGames
    .init()
    .then(ysdk => {
        console.log('Yandex SDK initialized');
        window.ysdk = ysdk;
    });

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

The error means you've tried to use SDK methods (ads, purchases, etc.) before initializing the SDK (the Yandex SDK initialized message should appear in the Games Console). If you don't know how to ensure the order of calls, rewrite the chunks of your code where you use the SDK. To do this, replace this line:

ysdk.adv.showFullscreenAdv()

with:

YaGames.init().then(ysdk => ysdk.adv.showFullscreenAdv())

SDK connection example

<!-- Yandex Games SDK -->
<script src="/sdk.js"></script>
<script>
    YaGames.init().then(ysdk => {
        // ...
    });
</script>

Note

Our support team can help publish finished games or WebApps 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:

Write to chat