---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com/dev/games/doc/en/sdk/sdk-events.md
  - https://yandex.com/dev/games/doc/hi/sdk/sdk-events.md
  - https://yandex.com/dev/games/doc/ko/sdk/sdk-events.md
  - https://yandex.com/dev/games/doc/ru/sdk/sdk-events.md
  - https://yandex.com/dev/games/doc/tr/sdk/sdk-events.md
  - https://yandex.com/dev/games/doc/vi/sdk/sdk-events.md
  - https://yandex.com/dev/games/doc/zh/sdk/sdk-events.md
  - href: en/sdk/sdk-events.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/en/llms.txt

# Events

<!-- source: en/_includes/script-common.md -->
<!-- source: en/_includes/script/index-js.md -->

<!-- endsource: en/_includes/script/index-js.md -->

<!-- source: en/_includes/script/requirements-js.md -->

<!-- endsource: en/_includes/script/requirements-js.md -->

<!-- source: en/_includes/script/image-modal-js.md -->

<!-- endsource: en/_includes/script/image-modal-js.md -->
<!-- endsource: en/_includes/script-common.md -->

## Pause and Resume Events {#pause-resume}

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 (items [1.3](https://yandex.com/dev/games/doc/en/concepts/requirements.md#1-3) and [4.7](https://yandex.com/dev/games/doc/en/concepts/requirements.md#4-7)).

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


### game_api_pause and game_api_resume events {#pause-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](https://yandex.com/dev/games/doc/en/sdk/sdk-game-events.md#gameplay). 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 {#pause-resume-example}

{% list tabs %}

- game_api_pause

    ```javascript showLineNumbers
    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.
    ```

- game_api_resume

    ```javascript showLineNumbers
    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.
    ```

{% endlist %}

&nbsp; {.empty}


### Fullscreen ad on game startup {#startup-fullscreen-ad}

{% note warning %}

The platform automatically shows fullscreen ads when launching any game.

{% endnote %}

Unlike ad units triggered via [ysdk.adv.showFullscreenAdv()](https://yandex.com/dev/games/doc/en/sdk/sdk-adv.md#full-screen-block), startup ads don't have direct callbacks. To handle them properly, track the `game_api_pause` and `game_api_resume` events:

1. When receiving `game_api_pause`, mute game audio and pause gameplay.
2. Wait for `game_api_resume` before resuming the game.

This is particularly important for games where audio and gameplay start immediately.

#### Startup ad handling example {#startup-ad-example}

```javascript showLineNumbers
let gameStarted = false;
let isPaused = false;

// Game initialization function.
function initGame() {
    // Subscribe to pause/resume events.
    ysdk.on('game_api_pause', handlePause);
    ysdk.on('game_api_resume', handleResume);

    // Check if we're not already paused.
    // If not, start the game immediately.
    if (!isPaused) {
        startGame();
    }
}

function handlePause() {
    isPaused = true;
    // Stop audio and gameplay.
    console.log('GAME PAUSED - waiting for resume');
}

function handleResume() {
    isPaused = false;

    // Start game if it wasn't launched yet.
    if (!gameStarted) {
        startGame();
    } else {
        // Resume audio and gameplay.
    }

    console.log('GAME RESUMED');
}

function startGame() {
    gameStarted = true;

    // Initialize audio.
    // Start game loop.
    console.log('GAME STARTED');
}

// Launch game initialization.
initGame();
```



## Other events {#other-events}

You can also track additional events triggered by user interactions with the application.

```typescript showLineNumbers
enum ESdkEventName {
    EXIT = 'EXIT',
    HISTORY_BACK = 'HISTORY_BACK',
    ACCOUNT_SELECTION_DIALOG_OPENED = 'ACCOUNT_SELECTION_DIALOG_OPENED',
    ACCOUNT_SELECTION_DIALOG_CLOSED = 'ACCOUNT_SELECTION_DIALOG_CLOSED',
}

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

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

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


### HISTORY_BACK event {#history-back}

{% note alert %}

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

{% endnote %}

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

```javascript showLineNumbers
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 {#exit}

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:

```javascript
ysdk.dispatchEvent(ysdk.EVENTS.EXIT);
```


### Game account selection dialog {#account-selection-dialog}

The platform saves game progress for both authorized and unauthorized players. A user might start playing without authorization and later sign in to an account. In this case, they'll have two separate progress tracks — one linked to their account and another anonymous one. The platform will show a dialog where users can compare saves by playtime, last login date, and other parameters to choose which progress to keep.

If you frequently sync player data or store game progress on your own server, monitor progress changes after account selection in this dialog.

The SDK provides two events for this:

- `ACCOUNT_SELECTION_DIALOG_OPENED` — dialog opening.
- `ACCOUNT_SELECTION_DIALOG_CLOSED` — dialog closing.

When the dialog opens, you may pause regular player data sync. When it closes — return to the main menu or restart the game and re-fetch the player object.

#### Example {#account-selection-dialog-example}

```javascript showLineNumbers
// Subscribe to account selection dialog opening.
ysdk.on(ysdk.EVENTS.ACCOUNT_SELECTION_DIALOG_OPENED, () => {
    // Pause player data synchronization.
});

// Subscribe to account selection dialog closing.
ysdk.on(ysdk.EVENTS.ACCOUNT_SELECTION_DIALOG_CLOSED, async () => {
    // Return to main menu or reload the page.
    // ...

    // Re-fetch player data.
    const player = await ysdk.getPlayer();
    const data = await player.getData();
});
```



---

<!-- source: en/_includes/sdk-support.md -->
{% note info %}

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](https://discord.com/invite/wU4p3whr4T){.external}.

{% endnote %}

If you are facing an issue or have a question regarding the use of Yandex Games SDK, please contact support:

<!-- source: en/_includes/button-chat.md -->
<a href="https://yandex.com/chat/#/user/a4fa5c06-75db-9b38-6eea-b1673785f7d5">
  <span class="button">Write to chat</span>
</a>
<!-- endsource: en/_includes/button-chat.md -->
<!-- endsource: en/_includes/sdk-support.md -->
