Create Leaderboard
For more detailed examples and guidance on implementing the Myria Leaderboard SDK, please refer to our TypeScript SDK samples on GitHub here. This repository includes practical examples demonstrating how to create, manage, and interact with leaderboards, making it easier for you to integrate leaderboard functionality into your projects.
To create a leaderboard using the @myria/leaderboard-ts-sdk
, follow the steps below.
Step 1: Initialize the Leaderboard Manager
First, you need to initialize the LeaderboardManager
with the appropriate parameters. These parameters include your environment type (e.g., STAGING
, PRODUCTION
) and the developerApiKey
you received from the Myria admin.
import { LeaderboardManager, InitLeaderboardParams, LeaderboardEnv } from '@myria/leaderboard-ts-sdk';
const developerApiKey = "YOUR_DEVELOPER_API_KEY";
const leaderboardParams: InitLeaderboardParams = {
env: LeaderboardEnv.staging, // Use your desired environment type
apiKey: developerApiKey,
};
const leaderboardManager = new LeaderboardManager(leaderboardParams);
Step 2: Define Leaderboard Parameters
Next, define the parameters for your leaderboard. This includes properties like the name of the leaderboard, description, game name, duration, and score update strategy.
import { CreateLeaderboardParams } from '@myria/leaderboard-ts-sdk';
const leaderboardParams: CreateLeaderboardParams = {
name: 'Test Leaderboard', // The name of your leaderboard
description: 'A test leaderboard', // A brief description of your leaderboard
gameName: 'Test Game', // The name of your game
livePeriodInDays: 10, // The duration for each leaderboard period
totalPeriods: 5, // The total number of periods for the leaderboard
updateScoreStrategy: 'ACCUMULATE', // Strategy for updating scores
availableAt: '2024-08-30', // Specify when the leaderboard becomes available (Format YYYY-MM-DD)
enableMetadata: false, // Optional: Enable metadata if needed
};
Input Details:
Mandatory Fields:
- name: string - The name of the leaderboard.
- description: string - A brief description of the leaderboard.
- updateScoreStrategy: string - Strategy for updating scores (e.g., ACCUMULATE, OVERWRITE).
- gameName: string - The name of the game associated with the leaderboard.
- totalPeriods: number - The total number of periods for the leaderboard.
- livePeriodInDays: number - The duration for each leaderboard period in days.
- availableAt: string - The date when the leaderboard becomes available (Format YYYY-MM-DD).
Optional Fields:
- enableMetadata: boolean - Whether to enable metadata for the leaderboard.
Step 3: Create the Leaderboard
Once you have defined the parameters, you can create the leaderboard by calling the createLeaderboard method on the LeaderboardManager instance.
const result = await leaderboardManager.createLeaderboard(leaderboardParams);
console.log('Leaderboard created:', result);
Output Details:
The response from the createLeaderboard
method includes the following fields:
Mandatory Fields:
- name: string - The name of the leaderboard.
- description: string - A brief description of the leaderboard.
- updateScoreStrategy: string - The strategy for updating scores.
- gameName: string - The name of the game associated with the leaderboard.
- livePeriodInDays: number - The duration for each leaderboard period in days.
- availableAt: string - The date when the leaderboard becomes available.
- status: string - The current status of the leaderboard.
- currentPeriod: number - The current active period of the leaderboard.
- dataPersistenceInDays: number - Number of days data will persist.
- expireAt: string - The date when the leaderboard expires.
- id: number - The unique identifier for the leaderboard.
Optional Fields:
- totalPeriods?: number - The total number of periods for the leaderboard (if provided).
- enableMetadata?: boolean - Whether metadata is enabled for the leaderboard.
- developerId?: string - The ID of the developer who created the leaderboard.
- updatedAt?: string - The timestamp when the leaderboard was last updated.
- createdAt?: string - The timestamp when the leaderboard was created.
- enablePeriodRefresh?: boolean - Whether period refresh is enabled.
Summary
By following these steps, you can successfully create a leaderboard using the @myria/leaderboard-ts-sdk
. This process involves initializing the LeaderboardManager, defining the leaderboard parameters, and invoking the createLeaderboard method to finalize the creation.
For more details on the available options and additional features, refer to the full documentation.