Skip to main content

Player Module

The Player Module provides access to player information and gamification preferences in the Gamanza Engage Web Client SDK.

Accessing the Module

The PlayerModule is initialized internally by the SDK and should not be instantiated directly. It's accessible through the main SDK instance.

// Example of accessing the PlayerModule through the SDK
const { Player } = GamanzaEngageWebClientSDK.getInstance();

Methods

getPlayer

Returns the current authenticated player information from the Gamanza Engage Platform.

Signature:

getPlayer(): Promise<PlayerData | null>

Returns:

TypeDescription
Promise<PlayerData | null>A promise that resolves to the player data or null if the player is missing or there is an error.

Example:

// Get player information
const player = await sdk.Player.getPlayer();
if (player) {
console.log(`Player ID: ${player.playerId}`);
console.log(`Player Name: ${player.firstName} ${player.lastName}`);

// Access gamification status
console.log(`Gamification Enabled: ${player.gamificationOpt.enable}`);

// Access ranks data if available
if (player.ranksData) {
console.log(`Current Rank: ${player.ranksData.rank.name}`);
console.log(`Current Level: ${player.ranksData.level.levelNumber}`);
console.log(`XP Balance: ${player.ranksData.xpBalance}`);
}

// Access wallet data if available
if (player.walletData) {
console.log(`Wallet Balance: ${player.walletData.balance}`);
}
}

playerGamificationOpts

Allows enabling or disabling the Gamanza Engage Gamification features for the current authenticated player.

Signature:

playerGamificationOpts(enable: boolean, reasons: Reason[]): Promise<SimpleResponse<void>>

Parameters:

NameTypeDescription
enablebooleanDefines if the player opts in (true) or opts out (false)
reasonsReason[]List of potential reasons why the player is opting out (required when opting out)

Returns:

TypeDescription
Promise<SimpleResponse<void>>A promise that resolves to a simple response indicating success or failure

Example:

// Opt out of gamification with reasons
const reasons = await sdk.Player.getListOfOptOutReasons();
const selectedReasons = [reasons[0]]; // Select first reason from the list

const response = await sdk.Player.playerGamificationOpts(false, selectedReasons);
if (response.ok) {
console.log('Successfully opted out of gamification');
} else {
console.error('Failed to opt out of gamification:', response.error);
}

// Opt in to gamification (no reasons needed)
const optInResponse = await sdk.Player.playerGamificationOpts(true, []);
if (optInResponse.ok) {
console.log('Successfully opted in to gamification');
}

getListOfOptOutReasons

Returns the list of predefined reasons configured in the Gamanza Engage Admin Instance to be displayed to the player when they decide to opt out of gamification.

Signature:

getListOfOptOutReasons(): Promise<Reason[]>

Returns:

TypeDescription
Promise<Reason[]>A promise that resolves to an array of predefined opt-out reasons

Example:

// Get list of opt-out reasons
const reasons = await sdk.Player.getListOfOptOutReasons();
console.log('Available opt-out reasons:');
reasons.forEach(reason => {
// Display the reason in the user's language if available
const translation = reason.translations?.find(t => t.language === userLanguage);
console.log(translation?.text || reason.option);
});

PlayerData

The main interface for player information.

interface PlayerData {
playerId: string;
firstName?: string;
lastName?: string;
gender?: string;
phone?: string;
username?: string;
email?: string;
language?: string;
currency?: string;
birthDate?: string;
nationality?: string;
address?: Address;
session?: PlayerSession;
gamificationOpt: GamificationOpt;
ranksData?: RanksData;
walletData?: WalletData;
}
PropertyTypeRequiredDescription
playerIdstringYesUnique identifier for the player
firstNamestringNoPlayer's first name
lastNamestringNoPlayer's last name
genderstringNoPlayer's gender
phonestringNoPlayer's phone number
usernamestringNoPlayer's username
emailstringNoPlayer's email address
languagestringNoPlayer's preferred language
currencystringNoPlayer's preferred currency
birthDatestringNoPlayer's birth date
nationalitystringNoPlayer's nationality
addressAddressNoPlayer's address information
sessionPlayerSessionNoPlayer's session information
gamificationOptGamificationOptYesPlayer's gamification preferences
ranksDataRanksDataNoPlayer's rank information
walletDataWalletDataNoPlayer's wallet information

Address

Interface for player address information.

interface Address {
country?: string;
city?: string;
street?: string;
postcode?: string;
}
PropertyTypeRequiredDescription
countrystringNoPlayer's country
citystringNoPlayer's city
streetstringNoPlayer's street address
postcodestringNoPlayer's postal code

PlayerSession

Interface for player session information.

interface PlayerSession {
registrationDate?: string;
registrationDevice?: string;
verificationDate?: string;
verificationChannel?: string;
numberDaysInLastTwoLogins?: number;
lastLoginDate?: string;
secondLastLoginDate?: string;
loginCount?: number;
lastLogoutDate?: string;
}
PropertyTypeRequiredDescription
registrationDatestringNoDate when the player registered
registrationDevicestringNoDevice used for registration
verificationDatestringNoDate when the player was verified
verificationChannelstringNoChannel used for verification
numberDaysInLastTwoLoginsnumberNoNumber of days between the last two logins
lastLoginDatestringNoDate of the player's last login
secondLastLoginDatestringNoDate of the player's second-to-last login
loginCountnumberNoTotal number of logins
lastLogoutDatestringNoDate of the player's last logout

GamificationOpt

Interface for player gamification preferences.

interface GamificationOpt {
enable: boolean;
reason?: Reason[];
resetPolicy?: Record<string, unknown>;
requestedByType?: string;
requestedBy?: string;
requestedAt?: string;
}
PropertyTypeRequiredDescription
enablebooleanYesWhether gamification is enabled for the player
reasonReason[]NoReasons for opting out of gamification
resetPolicyRecord<string, unknown>NoPolicy for resetting gamification
requestedByTypestringNoType of entity that requested the gamification status change
requestedBystringNoEntity that requested the gamification status change
requestedAtstringNoDate when the gamification status change was requested

Reason

Interface for opt-out reasons.

interface Reason {
option?: string;
translations?: Translation[];
}
PropertyTypeRequiredDescription
optionstringNoIdentifier for the reason
translationsTranslation[]NoTranslations of the reason text

Translation

Interface for translations.

interface Translation {
language?: string;
text?: string;
}
PropertyTypeRequiredDescription
languagestringNoLanguage code
textstringNoTranslated text

RanksData

Interface for player rank information.

interface RanksData {
_id: string;
playerId: string;
category: Category;
rank: Rank;
level: Level;
xpBalance: number;
createdAt: string;
updatedAt: string;
currency: string;
previousPeriod?: PreviousPeriod;
rankProgress: number;
levelProgress: number;
levelPosition?: LevelPosition;
pointsUntilNextLevel: number;
pointsUntilNextRank: number;
nextLevel?: Level;
nextRank?: Rank;
pointsToKeepRank?: number;
xpComparativePeriod?: string;
betActivity?: BetActivityType;
}
PropertyTypeRequiredDescription
_idstringYesUnique identifier for the ranks data
playerIdstringYesPlayer identifier
categoryCategoryYesRank category
rankRankYesCurrent rank
levelLevelYesCurrent level
xpBalancenumberYesCurrent XP balance
createdAtstringYesCreation date
updatedAtstringYesLast update date
currencystringYesCurrency used
previousPeriodPreviousPeriodNoData from the previous period
rankProgressnumberYesProgress towards the next rank (0-100)
levelProgressnumberYesProgress towards the next level (0-100)
levelPositionLevelPositionNoPosition within the current level
pointsUntilNextLevelnumberYesPoints needed to reach the next level
pointsUntilNextRanknumberYesPoints needed to reach the next rank
nextLevelLevelNoNext level information
nextRankRankNoNext rank information
pointsToKeepRanknumberNoPoints needed to maintain the current rank
xpComparativePeriodstringNoPeriod used for XP comparison
betActivityBetActivityTypeNoBetting activity information

Category

Interface for rank categories.

interface Category {
_id: string;
name: string;
}
PropertyTypeRequiredDescription
_idstringYesUnique identifier for the category
namestringYesCategory name

Rank

Interface for player ranks.

interface Rank {
_id: string;
name: string;
imageUrl: string;
translations: RanksTranslation[];
}
PropertyTypeRequiredDescription
_idstringYesUnique identifier for the rank
namestringYesRank name
imageUrlstringYesURL to the rank image
translationsRanksTranslation[]YesTranslations of the rank information

Level

Interface for player levels.

interface Level {
_id: string;
levelNumber: number;
}
PropertyTypeRequiredDescription
_idstringYesUnique identifier for the level
levelNumbernumberYesLevel number

WalletData

Interface for player wallet information.

interface WalletData {
_id: string;
balance: number;
createdAt: string;
updatedAt: string;
}
PropertyTypeRequiredDescription
_idstringYesUnique identifier for the wallet
balancenumberYesCurrent wallet balance
createdAtstringYesCreation date
updatedAtstringYesLast update date

SimpleResponse

Generic interface for simple responses.

interface SimpleResponse<T> {
ok: boolean;
data: T | null;
error?: {
code: string;
message: string;
};
}
PropertyTypeRequiredDescription
okbooleanYesWhether the operation was successful
dataT | nullYesResponse data (null for void responses)
error{ code: string; message: string; }NoError information if the operation failed