Remote Config

You can retrieve a remote flag configuration (Remote Config) by using the getFlags() method from the Yandex Games SDK. We recommend requesting the flags once at your game startup.

The getFlags() method returns the values of the saved flags. The following are the method usage examples:

const ysdk = await YaGames.init(); // Initializing the SDK.
const flags = await ysdk.getFlags(); // This method returns an object with flags.

// You can add this condition to your game logic:
if (flags.difficult === 'hard') {
    // Increasing the game difficulty.
}
YaGames.init()
    .then(ysdk => ysdk.getFlags())
    .then(flags => {
        // "flags" contains an object with flags.

        // You can add this condition to your game logic:
        if (flags.difficult === 'hard') {
            // Increasing the game difficulty.
        }
    });

Local configuration

We recommend always embedding local flag configuration in the game code to ensure that the game can access it even if there are network or other issues (for example, poor internet connection in the subway). This approach improves your game's operation.

For this purpose, the getFlags() method supports additional parameters. Pass the local configuration (a flat object containing string values) in the defaultFlags field.

The resulting object is a combination of your remote and local configurations. The remote configuration has a higher priority.

YaGames.init()
    .then(ysdk => ysdk.getFlags({ defaultFlags: { difficult: 'easy' } }))
    .then(flags => {
        // "flags" contains the object "{ difficult: 'easy' }"
    });

User parameters

If your game app stores the player state information, such as whether the player used in-game currency at least once, how many levels they've passed, or whether the user is considered a core player, you can add these details to the remote configuration. For more information on how to set up a conditional flag, see Create a flag configuration.

Pass the user parameters as an array in the clientFeatures field of the getFlags() method.

Example with "await"

const ysdk = await YaGames.init(); // Initializing the SDK.
const player = await ysdk.getPlayer(); // Retrieving the player.
const payingStatus = player.getPayingStatus(); // Fetching the user's payment activity status on the platform.

// Requesting the flags with the user parameter containing the user's payment activity status.
const flags = await ysdk.getFlags({
    clientFeatures: [
        {name: 'payingStatus', value: payingStatus}
    ]
});

Examples without "await"

// Sending the user parameter "levels=5".
YaGames.init()
    .then(ysdk => ysdk.getFlags({
        defaultFlags: {},
        clientFeatures: [
            { name: 'levels', value: '5' }
        ]})
    )
    .then(flags => {
        // User parameter condition is not met.
        // flags.showFullscreenAdOnStart === 'no'
    });

// Sending the user parameter "levels=10".
YaGames.init()
    .then(ysdk => ysdk.getFlags({
        defaultFlags: {},
        clientFeatures: [
            { name: 'levels', value: '10' }
        ]})
    )
    .then(flags => {
        // User parameter condition is met, showing ads at startup.
        // flags.showFullscreenAdOnStart === 'yes'
    });

// Example with two user parameters:
YaGames.init()
    .then(ysdk => ysdk.getFlags({
        defaultFlags: {},
        clientFeatures: [
            { name: 'levels', value: '10' },
            { name: 'inAppPurchaseUsed', value: 'yes' }
        ]})
    )
    .then(flags => {

    });

Signature and interfaces of the getFlags() method

interface IFlags {
    [key: string]: string;
}

interface ClientFeature {
    name: string;
    value: string;
}

interface IGetFlagsParams {
    defaultFlags?: IFlags;
    clientFeatures?: ClientFeature[];
}

function getFlags(getFlagsParams: IGetFlagsParams = {}): IFlags {}

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