Get Environment
The Get Environment feature in the Yandex Games SDK provides detailed information about the player’s environment. This data includes language preferences, platform details, and other contextual information that can help you optimize and personalize the player experience.
Overview
The EnvironmentData
class offers a structured way to access key environmental properties, including:
Language and Localization:
I18n.lang
provides the player’s language setting.Browser and Platform Data: Understand if the player is using a specific platform like Telegram or a Yandex domain.
App and Domain Info: Access the game’s
app.id
, current domain, and additional URL information.
Using this data effectively allows you to:
Localize the game experience based on language.
Tailor gameplay and UI based on platform or device type.
Collect contextual insights for analytics and optimization.
Structure of EnvironmentData
The EnvironmentData
class has the following properties:
app
: Contains application-specific data.id
: The application ID for your game.
browser
: Provides information on the browser language.lang
: The browser language, useful for localizing content.
data
: Holds URLs and domain data.baseUrl
: The main URL used to serve the game.secondDomain
: A secondary domain that may be used as a fallback.
i18n
: Handles internationalization settings.lang
: The player’s preferred language.tld
: The top-level domain, useful for region-based content.
isTelegram
: Indicates if the game is being played on Telegram.domain
: The primary domain serving the game.
Example Usage
Below is an example of retrieving environment data and using it to adjust language settings and display relevant domain information.
App ID and Domain: Use
environmentData.app.id
andenvironmentData.domain
for app-specific setups or analytics.Language Settings: Check
environmentData.i18n.lang
to set language preferences and ensure the game is displayed in the correct language.Platform-Specific UI: If
environmentData.isTelegram
is true, consider adjusting the UI or gameplay to cater to Telegram users.
Use Cases
Localization and Language Support
Use
i18n.lang
andbrowser.lang
to automatically adjust the language, currency, or date formats.Example: Set game text to Russian if
environmentData.i18n.lang == "ru"
.
Platform-Specific Adjustments
If the game runs on Telegram (
isTelegram == true
), show specialized UI or features tailored for Telegram users.Example: Enable specific controls or layouts optimized for Telegram’s layout.
Domain-Based Content and Fallback URLs
Use
data.baseUrl
anddata.secondDomain
to retrieve the game’s URLs, allowing fallback options if the primary domain is unavailable.Example: Use
secondDomain
as a backup for loading assets ifbaseUrl
is inaccessible.
App and Analytics Tracking
Use
app.id
anddomain
for internal analytics or tracking player interactions across different versions or entry points of the game.Example: Log
app.id
to track which version of the game is being played most frequently.
Best Practices
Cache Environment Data: Store the environment data at the start of the session to avoid repeated API calls.
Fallbacks for Language Settings: Provide a default language setting (like English) if
i18n.lang
does not match your supported languages.Use Domain Data for Troubleshooting: Log
baseUrl
andsecondDomain
for easier troubleshooting and analytics tracking.
Last updated
Was this helpful?