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.
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>
The SDK runs as a no-op when your game is served locally. To verify SDK integration correctness, use the test suite guide.
Integrate with Playables SDK
There are several required and optional integrations with the Playables SDK.
Required integrations
Review the publishing requirements overall, with a focus on integration requirements. Review the Playables SDK reference for implementation details.
Examples include:
ytgame.game.firstFrameReady()
ytgame.game.gameReady()
ytgame.IN_PLAYABLES_ENV
ytgame.system.isAudioEnabled()
ytgame.system.onAudioEnabledChange((isAudioEnabled) => {})
ytgame.system.onPause(() => {})
ytgame.system.onResume(() => {})
ytgame.game.loadData()
ytgame.game.saveData(data)
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.ytgame.engagement.sendScore({ value: newScore })
- Send a best score to YouTube to display.ytgame.engagement.openYTContent({ id: videoID })
- Open a YouTube video.ytgame.health.logError()
andytgame.health.logWarning()
- Log issues to YouTube.
Review the Playables SDK reference for implementation details and additional functions.
TypeScript type definitions
For games using TypeScript, download type definitions.
Samples games
Samples are available 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.