Skip to main content

Remote Configurations

GameAnalytics offers the option to set up remote configs in your dashboard that can be changed on the whim without needing to release a new version of the game. The remote configs are a custom set of key-value pairs.

Setup Remote Configurations​

GameAnalytics' Remote Configurations feature offers the ability to set up and tune values in your game's dashboard. These values can be changed on the whim without needing to release a new version of the game.

Set up your remote configs by following the Remote Configs guide.

Check Remote Config Updates in Lua​

The remote configs are fetched from the server shortly after the SDK starts, so they are not available immediately. The recommended way to react to them is a listener, which is called whenever the remote configs are received or refreshed:

gameanalytics.setRemoteConfigsListener(function(self)
local difficulty = gameanalytics.getRemoteConfigsValueAsNumber({ key = "difficulty", defaultValue = 1 })
local title = gameanalytics.getRemoteConfigsValueAsString({ key = "shop_title", defaultValue = "Shop" })
end)

Set the listener before the SDK starts so the first update is not missed. Since the SDK starts automatically with the game, enable manual initialization in game.project:

[gameanalytics]
manual_initialize = 1

Then register the listener and start the SDK from the same place:

function init(self)
gameanalytics.setRemoteConfigsListener(function(self)
-- the remote configs are ready, add your code here
end)

gameanalytics.initialize()
end

Manual Check for Remote Config Updates​

Instead of a listener you can check whether the remote configs have been populated:

if gameanalytics.isRemoteConfigsReady() then
-- the remote configs are ready, add your code here
end
warning

The isRemoteConfigsReady function will return false if the configs haven't been populated by the server yet.

info

The remote configs can be populated with an empty set if the device is offline and there are no cached remote configs from a previous session.

Retrieve Remote Config Values​

Read a single value by its key, with a default to fall back on:

-- as a string
local title = gameanalytics.getRemoteConfigsValueAsString({ key = "shop_title", defaultValue = "Shop" })

-- as a number
local difficulty = gameanalytics.getRemoteConfigsValueAsNumber({ key = "difficulty", defaultValue = 1 })

-- as a JSON string, for keys whose value is a JSON object
local rewards = gameanalytics.getRemoteConfigsValueAsJson("daily_rewards")

defaultValue is optional: without it the normal default value is returned.

warning

If the specified key is not found in the Remote Configs it will return the default value of either "normal" or "custom" value.

To parse the remote configs yourself, read the whole payload as a JSON string:

if gameanalytics.isRemoteConfigsReady() then
local configs = json.decode(gameanalytics.getRemoteConfigsContentAsString())
end