Skip to main content

Games

Usage

Open game

You can open a game using the method inAppStoryManager.openGame(gameId, appearanceManager).

Parameters:

ParameterTypeDescription
gameInstanceIdstring | numberUnique identifier of the game
appearanceManagerAppearanceManagerAppearance configuration
import { InAppStoryManager, AppearanceManager } from "@inappstory/js-sdk";

const openMyGame = async (gameId) => {
try {
const inAppStoryManager = new InAppStoryManager.getInstance();
const appearanceManager = new AppearanceManager();
await inAppStoryManager.openGame(gameId, appearanceManager);
} catch (error) {
console.error(error);
}
};

openMyGame("game-id");

Close game

You can close an opened game reader with the method:

inAppStoryManager.closeGame();

Example

For configuring game reader options, see <GameReaderOptions>.

<!DOCTYPE html>
<head>
<meta charset="utf-8" />
</head>
<html>
<body>
<script
defer
src="https://cdn.domain-placeholder/sdk/js-sdk-version-placeholder/dist/js/IAS.js"
></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
const inAppStoryManagerConfig = {
apiKey: "{project-integration-key}",
};

const inAppStoryManager = new window.IAS.InAppStoryManager(
inAppStoryManagerConfig,
);
const appearanceManager = new window.IAS.AppearanceManager();
appearanceManager.setGameReaderOptions({
/* your appearance options*/
});
inAppStoryManager
.openGame("{game-id}", appearanceManager)
.catch(console.error)

[("startGame", "closeGame")].forEach((eventName) =>
inAppStoryManager.on(eventName, (payload) =>
console.log("event", eventName, payload),
),
);
});
</script>
</body>
</html>

Appearance

PropertyTypeDescriptionDefault Value
loader.default.colorstringMain loader color"white"
loader.default.accentColortringAccent color of the loader"transparent"
loader.customstring?Custom loader SVG or component as a stringnull
closeButtonPosition"start" | "end"Position of the close button"end"
closeButton.svgSrc.baseStatestringSVG icon for the close button-
game.backdropColortringBackground color of the game container"rgb(51, 51, 51)"
borderRadiusnumberBorder radius of the main container5
backdrop.opacitynumberOpacity of the backdrop while loading the game1
backdrop.backgroundstringBackground color of the backdrop"#1a1a1a"

Events

import { InAppStoryManager } from "@inappstory/js-sdk";

const inAppStoryManager = new InAppStoryManager({ apiKey: "{projectToken}" });
inAppStoryManager.on("startGame", (payload) => console.log(payload));


startGame

Description: Fired when a game starts.

Payload:

FieldTypeDescription
idstringUnique game ID

closeGame

Description: Fired when a game is closed.


eventGame

Description: Fired when a custom game event occurs.

Payload:

FieldTypeDescription
namestringName of the event
payloadanyEvent-specific payload