YouTube Playables SDK is a web SDK for connecting web games with the
YouTube environment. The SDK features a robust API to support games in a
variety of ways to create an excellent gaming experience on YouTube.

1. [Add the SDK](https://developers.google.com/youtube/gaming/playables/reference/getting_started#add_the_playables_sdk_to_your_game)
2. [Integrate](https://developers.google.com/youtube/gaming/playables/reference/getting_started#integrate_with_playables_sdk)
3. [Test](https://developers.google.com/youtube/gaming/playables/reference/getting_started#test_your_game_with_the_test_suite)

## Add the Playables SDK to your game

A game should have an `index.html` file in the root directory. Import the
YouTube Playables SDK by adding this line before any of your game code:

    <script src="https://www.youtube.com/game_api/v1"></script>

> [!IMPORTANT]
> **Important:** The SDK **MUST** be loaded before any of your game code. This creates a reproducible, sandboxed environment and make certain functions available to the game immediately. This is validated during publishing and you can follow the [test suite guide](https://developers.google.com/youtube/gaming/playables/reference/test_suite_guide) to validate before submitting your game.

> [!NOTE]
> **Note:** The SDK runs as a no-op when your game is served locally. To verify SDK integration correctness, use the [test suite guide](https://developers.google.com/youtube/gaming/playables/reference/test_suite_guide).

## Integrate with Playables SDK

There are several required and optional integrations with the Playables SDK.

### Required integrations

Review the [publishing requirements](https://developers.google.com/youtube/gaming/playables/certification/requirements) overall, with a focus on [integration
requirements](https://developers.google.com/youtube/gaming/playables/certification/requirements_integration). Review the [Playables SDK reference](https://developers.google.com/youtube/gaming/playables/reference/sdk) for implementation details.

Examples include:
Loading

- [`ytgame.game.firstFrameReady()`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.game.firstFrameReady)
- [`ytgame.game.gameReady()`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.game.gameReady)
- [`ytgame.IN_PLAYABLES_ENV`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.IN_PLAYABLES_ENV)
Audio

- [`ytgame.system.isAudioEnabled()`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.system.isAudioEnabled)
- [`ytgame.system.onAudioEnabledChange((isAudioEnabled) => {})`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.system.onAudioEnabledChange)
Pause and resume

- [`ytgame.system.onPause(() => {})`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.system.onPause)
- [`ytgame.system.onResume(() => {})`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.system.onResume)
Cloud save

- [`ytgame.game.loadData()`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.game.loadData)
- [`ytgame.game.saveData(data)`](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.game.saveData)

### Recommended integrations

In addition to the required integrations, several other functions are available
to create a highly engaging experience. Examples include:
[`ytgame.system.getLanguage()`
Use this to retrieve the user's current locale setting. Don't use other functions or store the language in the cloud save, as this may change at any time.](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.system.getLanguage) [`ytgame.engagement.sendScore({ value: newScore })`
Send a best score to YouTube to display.](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.engagement.sendScore) [`ytgame.engagement.openYTContent({ id: videoID })`
Open a YouTube video.](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.engagement.openYTContent) [`ytgame.health.logError()` and `ytgame.health.logWarning()`
Log issues to YouTube.](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.health) [`ytgame.ads.requestInterstitialAd()` and `requestRewardedAd(rewardId: string)`
Integrate ads features into your game.](https://developers.google.com/youtube/gaming/playables/reference/sdk#ytgame.ads)

Review the [Playables SDK reference](https://developers.google.com/youtube/gaming/playables/reference/sdk) for implementation details and additional
functions.

### TypeScript type definitions

For games using TypeScript,
[download
type definitions](https://www.youtube.com/playablesportal/static/youtube_ytgame_web_deploy_mpm_files/index.d.ts).

### Sample games

[Samples are
available](https://developers.google.com/youtube/gaming/playables/samples/oss_samples) that demonstrate how to integrate with YouTube Playables
SDK, including plain JavaScript, Flutter web, Godot, and Unity.

## Test your game with the test suite

Once you are ready, you can validate your integration using the test
suite. To learn how, follow the
[test suite
guide](https://developers.google.com/youtube/gaming/playables/reference/test_suite_guide).
[Test suite
guide](https://developers.google.com/youtube/gaming/playables/reference/test_suite_guide)