Zilana SDK
The Zilana SDK is a lightweight library for managing player sessions, tracking events, and syncing data with a backend server. This guide explains the available public methods and provides examples for integration.
Installation
npm i @telazer/zilana_client_sdk
Configuration
The SDK requires configuration details such as userId
, gameId
, and a mapping of event names to eventId
s.
Initialization
Method: initialize
Initializes the SDK, setting up sessions and enabling event tracking.
**Parameters
**:
config
: An object containing:userId
: The unique identifier for the user.gameId
: The unique identifier for the game.eventMap
: A key-value pair mapping event names to their corresponding IDs.debug
(optional): Enables debug logging if set to true
.
**Example
**:
import { Zilana } from './zilana-sdk';
const config = {
userId: '<UUID>',
gameId: '<UUID>',
};
const eventMap = {
USER_LOGGED_IN: '<UUID>',
LEVEL_COMPLETED: '<UUID>',
ITEM_PURCHASED: '<UUID>',
};
Zilana.initialize({ config, eventMap, debug: true });
Public Methods
1. recordEvent
Records an event for the current active session.
**Parameters
**:
eventName
: The name of the event to be recorded. Must exist in the eventMap
provided during initialization.
Example:
Zilana.recordEvent('LEVEL_COMPLETED');
Features
- Automatic
Session Management: Sessions are automatically created when the SDK initializes.
- **Event Tracking
**: Record custom events and associate them with active sessions.
- **Health Checks
**: Regular integrity checks for session and player data.
- **Debug Logging
**: Detailed logs for debugging when
debug
is enabled.
Local Storage
The SDK uses the browser's localStorage
to persist session data under the key com.telazer.zilana-data
.
Debugging
Enable debug mode during initialization:
Zilana.initialize({ config, eventMap, debug: true });
This will log all informational and warning messages to the console.
Example Usage
import { Zilana } from './zilana-sdk';
const config = {
userId: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
gameId: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
};
const eventMap = {
USER_LOGGED_IN: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
LEVEL_COMPLETED: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
ITEM_PURCHASED: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
};
Zilana.initialize({ config, eventMap, debug: true });
Zilana.recordEvent('USER_LOGGED_IN');
Zilana.recordEvent('LEVEL_COMPLETED');
Support
For assistance or to report issues, contact the development team at
dev@telazer.com.