Module: session
Table of contents
Functions
- gameplayStart
- gameplayStop
- getDevice
- getEntryPointAsync
- getEntryPointData
- getLocale
- getOrientation
- getPlatform
- getTrafficSource
- happyTime
- onOrientationChange
- setSessionData
- switchGameAsync
Functions
gameplayStart
▸ gameplayStart(): void
Tracks the start of a gameplay session, including resuming play after a break. Call whenever the player starts playing or resumes playing after a break (menu/loading/achievement screen, game paused, etc.).
Example
Returns
void
gameplayStop
▸ gameplayStop(): void
Tracks the end of a gameplay session, including pausing play or opening a menu. Call on every game break (entering a menu, switching level, pausing the game, ...)
Example
Returns
void
getDevice
▸ getDevice(): Device
Gets the device the player is using. This is useful for device specific code.
Example
Returns
Device the player is using.
getEntryPointAsync
▸ getEntryPointAsync(): Promise
<string
>
Returns the entry point that the game was launched from.
Example
Returns
Promise
<string
>
Promise that resolves with the name of the entry point from which the user started the game.
Throws
- NOT_SUPPORTED
- RETHROW_FROM_PLATFORM
getEntryPointData
▸ getEntryPointData(): Record
<string
, unknown
>
Returns any data object associated with the entry point that the game was launched from.
The contents of the object are developer-defined, and can occur from entry points on different platforms. This will return null for older mobile clients, as well as when there is no data associated with the particular entry point.
Example
Returns
Record
<string
, unknown
>
Data about the entry point or an empty object if none exists.
getLocale
▸ getLocale(): string
Gets the locale the player is using. This is useful for localizing your game.
Example
Returns
string
Locale in BCP47 format.
getOrientation
▸ getOrientation(): Orientation
Gets the orientation of the device the player is using. This is useful for determining how to display the game.
Example
const orientation = Wortal.session.getOrientation();
if (orientation === 'portrait') {
// Render portrait mode.
}
Returns
Orientation
Orientation of the device the player is using.
getPlatform
▸ getPlatform(): Platform
Gets the platform the game is running on. This is useful for platform specific code. For example, if you want to show a different social share asset on Facebook than on Link.
Example
Returns
Platform
Platform the game is running on.
getTrafficSource
▸ getTrafficSource(): TrafficSource
Gets the traffic source info for the game. This is useful for tracking where players are coming from. For example, if you want to track where players are coming from for a specific campaign.
Example
const source = Wortal.session.getTrafficSource();
console.log(source['r_entrypoint']);
console.log(source['utm_source']);
Returns
TrafficSource
URL parameters attached to the game.
happyTime
▸ happyTime(): void
The happyTimeAsync method can be called on various player achievements (beating a boss, reaching a high score, etc.). It makes the website celebrate (for example by launching some confetti). There is no need to call this when a level is completed, or an item is obtained.
Example
Returns
void
onOrientationChange
▸ onOrientationChange(callback
): void
Assigns a callback to be invoked when the orientation of the device changes.
Example
Wortal.session.onOrientationChange(orientation => {
if (orientation === 'portrait') {
// Render portrait mode
}
});
Parameters
Name | Type | Description |
---|---|---|
callback |
(orientation: Orientation) => void |
Callback to be invoked when the orientation of the device changes. |
Returns
void
setSessionData
▸ setSessionData(data
): void
Sets the data associated with the individual gameplay session for the current context.
This function should be called whenever the game would like to update the current session data. This session data may be used to populate a variety of payloads, such as game play webhooks.
Example
Parameters
Name | Type | Description |
---|---|---|
data |
Record <string , unknown > |
An arbitrary data object, which must be less than or equal to 1000 characters when stringified. |
Returns
void
switchGameAsync
▸ switchGameAsync(gameID
, data?
): Promise
<void
>
Request to switch to another game. The API will reject if the switch fails - else, the client will load the new game.
Example
Parameters
Name | Type | Description |
---|---|---|
gameID |
string |
ID of the game to switch to. The application must be a Wortal game. |
data? |
object |
An optional data payload. This will be set as the entrypoint data for the game being switched to. Must be less than or equal to 1000 characters when stringified. |
Returns
Promise
<void
>
Promise that resolves when the game has switched. If the game fails to switch, the promise will reject.
Throws
- INVALID_PARAMS
- USER_INPUT
- PENDING_REQUEST
- CLIENT_REQUIRES_UPDATE
- NOT_SUPPORTED