Events

Pause and Resume Events

Using the game_api_pause and game_api_resume events, the platform informs the game to pause or resume the gameplay process. These events simplify the integration process with our platform and help comply with moderation requirements (points 1.3 and 4.7).

Games that support pause and resume events can be additionally distributed on external platforms.

game_api_pause and game_api_resume Events

These events will help you track:

  • displaying and closing of full-screen or rewarded ads;
  • opening and closing of purchase windows;
  • switching browser tabs;
  • minimizing and maximizing the browser window.

They are aligned with the gameplay markup methods. When game_api_pause is triggered, the GameplayAPI.stop() method is called, and when game_api_resume is triggered, GameplayAPI.start() is executed.

If the game has already been stopped using the GameplayAPI.stop() method (for example, when the player opens a menu) and then the game_api_pause event occurs, the GameplayAPI.start() method will not be called upon the subsequent game_api_resume event. This allows preserving the current game state without disrupting the gameplay logic.

Use the on() and off() methods from the Yandex Games SDK to subscribe and unsubscribe from events accordingly.

Example

const pauseCallback = () => {
    pauseGame(); // Your function that stops the game loop and music.
    console.log('GAME PAUSED');
};

ysdk.on('game_api_pause', pauseCallback); // Subscribing to 'game_api_pause' events.
ysdk.off('game_api_pause', pauseCallback); // Unsubscribing from 'game_api_pause' events.
const resumeCallback = () => {
    resumeGame(); // Your function that resumes the game loop and music.
    console.log('GAME RESUMED');
};

ysdk.on('game_api_resume', resumeCallback ); // Subscribing to 'game_api_resume' events.
ysdk.off('game_api_resume', resumeCallback ); // Unsubscribing from 'game_api_resume' events.

Game Exit Events

You can track events that occur when the user clicks certain buttons in the game.

enum ESdkEventName {
    EXIT = 'EXIT',
    HISTORY_BACK = 'HISTORY_BACK'
}

ysdk = {
    EVENTS: {
        EXIT: ESdkEventName.EXIT,
        HISTORY_BACK: ESdkEventName.HISTORY_BACK
    },

    dispatchEvent(eventName: ESdkEventName, detail?: object): Promise<unknown> {},

    on(eventName: ESdkEventName, listener: Function): () => void {}
};

HISTORY_BACK event

Alert

This event is available only if the game is launched on a TV.

To track clicks on the Back button, use the following method:

ysdk.on(ysdk.EVENTS.HISTORY_BACK, () => {
    // Showing the custom game dialog to the user with the options
    // to confirm exiting the game, going to the internal settings, store, and so on
});

EXIT event

If the user confirms exiting the game in the custom dialog box that pops up after clicking Back, the game must send an exit event. To do this, use the following method:

ysdk.dispatchEvent(ysdk.EVENTS.EXIT);

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:

Write to chat