remote_config - YoYoGames/GMEXT-Firebase GitHub Wiki
Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update. When using Remote Config, you create in-app default values that control the behavior and appearance of your app. Then, you can later use the Firebase console or the Remote Config backend APIs to override in-app default values for all app users or for segments of your user base. Your app controls when updates are applied, and it can frequently check for updates and apply them with a negligible impact on performance. Check the official page for more information.
Before you can start using any Firebase module extensions you are required to follow some initial configuration. However if you've already done these for any of the other modules you can skip this configuration section and go straight to using the API functions.
- Create Project
- Platform Setup (Remote Config enabling steps are required)
The following functions are given for working with the Firebase Remote Config extension:
- FirebaseRemoteConfig_FetchAndActivate
- FirebaseRemoteConfig_GetDouble
- FirebaseRemoteConfig_GetKeys
- FirebaseRemoteConfig_GetString
- FirebaseRemoteConfig_Initialize
- FirebaseRemoteConfig_Reset
- FirebaseRemoteConfig_SetDefaultsAsync
- FirebaseRemoteConfig_AddOnConfigUpdateListener
This function asynchronously fetches and then activates the fetched configs. If the time elapsed since the last fetch from the Firebase Remote Config backend is more than the set minimum fetch interval, configs are fetched from the backend. After the fetch is complete, the configs are activated so that the fetched key-value pairs take effect.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
FirebaseRemoteConfig_FetchAndActivate()
Returns:
N/A
Triggers:
Key | Type | Description |
---|---|---|
type | String | The string "FirebaseRemoteConfig_FetchAndActivate"
|
success | Boolean | Whether or not the function task succeeded. |
Example:
FirebaseRemoteConfig_FetchAndActivate();
In the code above we are fetching and activating the Remote Config data from the Firebase servers. The function callback can be caught inside a Social Async Event.
if (async_load[? "type"] == "FirebaseRemoteConfig_FetchAndActivate")
{
if (async_load[? "success"])
{
var _keysJSON = FirebaseRemoteConfig_GetKeys();
var _keys = json_parse(_keysJSON);
var _count = array_length(_keys);
show_debug_message("Remote Config Data:");
for(var i = 0 ; i < _count; i++)
{
var _key = _keys[i];
show_debug_message("key: " + FirebaseRemoteConfig_GetString(_key));
}
}
}
The code above matches the response against the correct event type, and if the function task succeeded it gets all keys (using the function FirebaseRemoteConfig_GetKeys) that are afterwards parsed into an array (using the json_parse function). Finally it gets all their values as strings (using FirebaseRemoteConfig_GetString and logs them to the console.
This function returns the parameter value for the given key as a real. It evaluates the value of the parameter in the following order:
- The activated value, if the last successful FirebaseRemoteConfig_FetchAndActivate contained the key.
- The default value, if the key was set with FirebaseRemoteConfig_SetDefaultsAsync.
- The default real value:
0
(zero).
Syntax:
FirebaseRemoteConfig_GetDouble(key)
Argument | Type | Description |
---|---|---|
key | String | The key of the remote config parameter to get the value from. |
Returns:
N/A
Example:
var _magicNumber = FirebaseRemoteConfig_GetDouble("MagicNumber");
The code above reads the double value parameter for the key "MagicNumber"
that is stored in the Remote Config Extension map.
Returns a JSON formatted string of all the available keys.
Syntax:
FirebaseRemoteConfig_GetKeys()
Returns:
Example:
var _keysJSON = FirebaseRemoteConfig_GetKeys();
var _keys = json_parse(_keysJSON);
var _count = array_length(_keys);
show_debug_message("Remote Config Data:");
for(var i = 0 ; i < _count; i++)
{
var _key = _keys[i];
show_debug_message("key: " + FirebaseRemoteConfig_GetString(_key)));
}
The code above gets all keys (using the function FirebaseRemoteConfig_GetKeys) that are afterwards parsed into an array (using the json_parse function). Finally it gets all their values as strings (using FirebaseRemoteConfig_GetString and logs them to the console.
This function returns the parameter value for the given key as a string. It evaluates the value of the parameter in the following order:
- The activated value, if the last successful FirebaseRemoteConfig_FetchAndActivate contained the key.
- The default value, if the key was set with FirebaseRemoteConfig_SetDefaultsAsync.
- The default string value:
""
(empty string).
Syntax:
FirebaseRemoteConfig_GetString(key)
Argument | Type | Description |
---|---|---|
key | String | The key of the remote config parameter to get the value from. |
Returns:
Example:
var _configuration = FirebaseRemoteConfig_GetString("Configuration");
The code above reads the string value parameter for the key "Configuration"
that is stored in the Remote Config Extension map.
This function initializes the Firebase Remote Config extension and sets the minimum interval between successive fetch calls. Any fetches performed within the interval of the last fetch will use values returned during that fetch.
Note
The default fetch interval is 3600 seconds.
Syntax:
FirebaseRemoteConfig_Initialize(fetchInterval)
Argument | Type | Description |
---|---|---|
fetchInterval | Real | The minimum fetch Interval duration in seconds. |
Returns:
N/A
Example:
FirebaseRemoteConfig_Initialize(1000);
The code above initializes the Firebase Remote Config extension and sets the fetch interval to 1000
seconds.
This function deletes all activated, fetched and defaults configs and resets all Firebase Remote Config settings.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
FirebaseRemoteConfig_Reset()
Returns:
N/A
Triggers:
Key | Type | Description |
---|---|---|
type | String | The string "FirebaseRemoteConfig_Reset"
|
success | Boolean | Whether or not the function task succeeded. |
Example:
FirebaseRemoteConfig_Reset();
In the code above we request for the reset of the Remote Config value. The function callback can be caught inside a Social Async Event.
if (async_load[? "type"] == "FirebaseRemoteConfig_Reset")
{
if (async_load[? "success"])
{
show_debug_message("FirebaseRemoteConfig_Reset() SUCCEEDED");
}
else
{
show_debug_message("FirebaseRemoteConfig_Reset() FAILED");
}
}
The code above matches the response against the correct event type, and logs the success of the operation.
This function asynchronously sets the default configs using the given JSON formatted string with a set of key-value pairs. Contained values can only be strings or reals.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
FirebaseRemoteConfig_SetDefaultsAsync(jsonString)
Argument | Type | Description |
---|---|---|
jsonString | String | The JSON formatted representation of a struct with default key/value pairs. |
Returns:
N/A
Triggers:
Key | Type | Description |
---|---|---|
type | String | The string "FirebaseRemoteConfig_SetDefaultsAsync"
|
success | Boolean | Whether or not the function task succeeded. |
Example:
var _jsonData = { name: "John", age: 10 };
FirebaseRemoteConfig_SetDefaultsAsync(json_stringify(_jsonData));
In the code above we request to set the default values for the parameters inside the struct (_jsonData
) the struct is then converted to JSON formatted string (using the built-in function json_stringify). The function callback can be caught inside a Social Async Event.
if (async_load[? "type"] == "FirebaseRemoteConfig_SetDefaultsAsync")
{
if (async_load[? "success"])
{
show_debug_message("Default values were set successfully!");
}
else
{
show_debug_message("Default values failed to be set!");
}
}
The code above matches the response against the correct event type, and logs the success of the operation.
This function starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the RC backend when they are available.
Note
This function is only available on Android and iOS.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
FirebaseRemoteConfig_AddOnConfigUpdateListener()
Returns:
N/A
Triggers:
Key | Type | Description |
---|---|---|
type | String | The string "FirebaseRemoteConfig_AddOnConfigUpdateListener"
|
keys | String | An JSON-encoded array of strings |
success | Boolean | Whether successful |
Example:
/// Create Event
if(os_type == os_android or os_type == os_ios)
{
FirebaseRemoteConfig_AddOnConfigUpdateListener();
}
In the Create Event, the function is called if os_type is either os_android
or os_ios
.
/// Async Social Event
switch(async_load[?"type"])
{
// @triggered by FirebaseRemoteConfig_FetchAndActivate()
case "FirebaseRemoteConfig_AddOnConfigUpdateListener":
if(async_load[?"success"])
{
var _arr_strings = json_parse(async_load[?"keys"]);
array_foreach(_arr_strings, show_debug_message);
}
break;
// Other cases..
}
In the Social Async Event, the event type is checked. The "FirebaseRemoteConfig_AddOnConfigUpdateListener"
event type indicates a config update.
If the update is successful, the "keys"
value is parsed using json_parse and the value of each string in the resulting array is output in a debug message (going through all items using array_foreach).