Skip to content

How to Start

Initialization

The first step is to init the Balancy SDK, it might take some time depending on your content size and the init setup. The SDK will download the necessary data from the server and cache it locally. The SDK will also check for updates periodically. Usually the initialization is complete within a second, but in some cases might take longer.

var config = new AppConfig
{
    ApiGameId = "<GAME_ID>",
    PublicKey = "<PUBLIC_KEY>",
    Environment = Constants.Environment.Development,
    OnProgressUpdateCallback = (fileName, progress) =>
    {
        Debug.Log($"Launch progress {(int)(progress * 100)}% - {fileName}");
    }
};
Balancy.Main.Init(config);
const config = AppConfig.create({
    apiGameId: "<GAME_ID>",
    publicKey: "<PUBLIC_KEY>",
    environment: Environment.Development,
});
await Balancy.Main.init(config);

Initialization Parameters

Explore and customize your initialization with the following parameters to enhance your game’s integration with Balancy:

Mandatory Parameters

Mandatory Parameters Default Value Description
ApiGameId null A unique GUID associated with your game.
PublicKey null Essential public key needed for various game operations.
Environment Development Specifies the Balancy connection environment. Learn More.

Mandatory parameters are crucial for the initialization process and must be provided to ensure a successful connection with Balancy. You can find them in the dashboard of your game project.

Additional Parameters

Additional Parameters Default Value Description
AutoLogin true When true, the user is automatically authenticated by device ID during initialization.
Platform autodetect Identifies the platform used at launch, vital for payments and analytics.
LaunchType All Defines which data Balancy can use: Local and/or Cloud.
UpdateType FullUpdate Dictates the type and extent of content updates during runtime.
UpdatePeriod 600 Defines the time (in seconds) between subsequent attempts to update data.
OnProgressUpdateCallback null A callback showing the loading progress of Balancy.
CustomId "" The Id of the user associated with any third party system, it can be your own server-id.

In most cases you don't need to change additional parameters, but they can be useful for customizing the initialization process to suit your game's requirements.

Optional Parameters

Optional Parameters Default Value Description
DeviceId autodetect The unique device id, we use it for authentication.
AppVersion autodetect The version of the application, for instance "1.0.0".
EngineVersion autodetect The engine version. For instance "Unity 2022.3.25f1".
BranchName autodetect The branch Balancy should connect to. The branch is selected automatically using AppVersion and Environment, if left blank.

Optional parameters are usually used for testing purposes only. They can be useful for debugging and testing different scenarios in your game. The real values are automatically detected by Balancy, if left blank.

Callbacks

Balancy SDK provides various callbacks you can subscribe to. Some callbacks are informational, while others are essential for the game to function properly.

Mandatory Callbacks

Balancy.Callbacks.OnDataUpdated += status => 
        Debug.Log("OnDataUpdated Cloud = " + status.IsCloudSynched + 
                  " ;CMS = " + status.IsCMSUpdated + 
                  " ;Profiles = " + status.IsProfileUpdated);
Balancy.Callbacks.onDataUpdated = (status =>
    console.log("OnDataUpdated Cloud = " + status.isCloudSynched +
                " ;CMS = " + status.isCMSUpdated +
                " ;Profiles = " + status.isProfileUpdated));
Parameter Description
IsCloudSynched This flag shows if the data is synchronized with the cloud or not.
IsCMSUpdated Was the config's data changed since the previous callback.
IsProfileUpdated Was profile changed since the previous callback.

Init Flow Screenshot

Additional Callbacks

Balancy.Callbacks.OnAuthFailed += status => Debug.Log("OnAuthFailed: " + status.Message);
Balancy.Callbacks.OnCloudProfileFailedToLoad += status => Debug.Log("OnCloudProfileFailedToLoad: " + status.Message);
Balancy.Callbacks.onAuthFailed = (status => console.log("OnAuthFailed: " + status.message));
Balancy.Callbacks.onCloudProfileFailedToLoad = (status => console.log("OnCloudProfileFailedToLoad: " + status.message));

LiveOps Callbacks

Balancy.Callbacks.OnNewEventActivated += eventInfo => Debug.Log("OnNewEventActivated: " + eventInfo?.GameEvent?.Name);
Balancy.Callbacks.OnEventDeactivated += eventInfo => Debug.Log("OnEventDeactivated: " + eventInfo?.GameEvent?.Name);
Balancy.Callbacks.OnNewOfferActivated += offerInfo => Debug.Log("OnNewOfferActivated: " + offerInfo?.GameOffer?.Name);
Balancy.Callbacks.OnOfferDeactivated += (offerInfo, wasPurchased) => Debug.Log(" => Balancy.OnOfferDeactivated: " + offerInfo?.GameOffer?.Name + " ; wasPurchased = " + wasPurchased);
Balancy.Callbacks.OnNewOfferGroupActivated += offerGroupInfo => Debug.Log("OnNewOfferGroupActivated: " + offerGroupInfo?.GameOfferGroup?.Name);
Balancy.Callbacks.OnOfferGroupDeactivated += offerGroupInfo => Debug.Log("OnOfferGroupDeactivated: " + offerGroupInfo?.GameOfferGroup?.Name);
Balancy.Callbacks.OnNewAbTestStarted += abTestInfo => Debug.Log("OnNewAbTestStarted: " + abTestInfo?.Test?.Name);
Balancy.Callbacks.OnAbTestEnded += abTestInfo => Debug.Log("OnAbTestEnded: " + abTestInfo?.Test?.Name);
Balancy.Callbacks.OnSegmentInfoUpdated += segmentInfo => Debug.Log("OnSegmentInfoUpdated: " + segmentInfo?.Segment?.Name + " isIn = " + segmentInfo?.IsIn);
Balancy.Callbacks.onNewEventActivated = (eventInfo => console.log("OnNewEventActivated: " + eventInfo?.gameEvent?.name));
Balancy.Callbacks.onEventDeactivated = (eventInfo => console.log("OnEventDeactivated: " + eventInfo?.gameEvent?.name));
Balancy.Callbacks.onNewOfferActivated = (offerInfo => console.log("OnNewOfferActivated: " + offerInfo?.gameOffer?.name));
Balancy.Callbacks.onOfferDeactivated = (offerInfo, wasPurchased) => console.log("OnOfferDeactivated: " + offerInfo?.gameOffer?.name + " wasPurchased = " + wasPurchased);
Balancy.Callbacks.onNewOfferGroupActivated = (offerGroupInfo => console.log("OnNewOfferGroupActivated: " + offerGroupInfo?.gameOfferGroup?.name));
Balancy.Callbacks.onOfferGroupDeactivated = (offerGroupInfo => console.log("OnOfferGroupDeactivated: " + offerGroupInfo?.gameOfferGroup?.name));
Balancy.Callbacks.onNewAbTestStarted = (abTestInfo => console.log("OnNewAbTestStarted: " + abTestInfo?.test?.name));
Balancy.Callbacks.onAbTestEnded = (abTestInfo => console.log("OnAbTestEnded: " + abTestInfo?.test?.name));
Balancy.Callbacks.onSegmentInfoUpdated = (segmentInfo => console.log("OnSegmentInfoUpdated: " + segmentInfo?.segment?.name + " isIn = " + segmentInfo?.isIn));

Init Flow

Init Flow Screenshot