Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 5.0.0

### Added

- **Remote Configs With JSON**: Remote Configs now support JSON values, allowing for more complex configurations.
- **Playtime Metrics API**: Introduced new API to get total playtime and playtime in the current session.

## 4.1.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion source/gameanalytics/GACommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace gameanalytics
class GAState;
}

constexpr const char* GA_VERSION_STR = "cpp 4.1.0";
constexpr const char* GA_VERSION_STR = "cpp 5.0.0";

constexpr int MAX_CUSTOM_FIELDS_COUNT = 50;
constexpr int MAX_CUSTOM_FIELDS_KEY_LENGTH = 64;
Expand Down
51 changes: 33 additions & 18 deletions source/gameanalytics/GAState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ namespace gameanalytics
out["user_id"] = getUserId();

// remote configs configurations
if(getInstance()._configurations.is_object() && !getInstance()._configurations.empty())
if(getInstance()._trackingRemoteConfigsJson.is_array() && !getInstance()._trackingRemoteConfigsJson.empty())
{
out["configurations_v3"] = getInstance().getRemoteConfigAnnotations();
}
Expand Down Expand Up @@ -895,7 +895,7 @@ namespace gameanalytics

json contents;

for(auto& obj : getInstance()._configurations)
for(auto& obj : getInstance()._gameRemoteConfigsJson)
{
if(obj.contains("key") && obj.contains("value"))
{
Expand All @@ -910,10 +910,34 @@ namespace gameanalytics
return contents.dump(JSON_PRINT_INDENT);
}

void GAState::buildRemoteConfigsJsons(const json& remoteCfgs)
{
_gameRemoteConfigsJson = json::array();
_trackingRemoteConfigsJson = json::array();

for (const auto& configuration : remoteCfgs)
{
_gameRemoteConfigsJson.push_back({
{"key", configuration["key"]},
{"value", configuration["value"]}
});

_trackingRemoteConfigsJson.push_back({
{"key", configuration["key"]},
{"id", configuration["id"]},
{"vsn", configuration["vsn"]}
});
}

logging::GALogger::d("Remote configs: %s", _gameRemoteConfigsJson.dump(JSON_PRINT_INDENT).c_str());
logging::GALogger::d("Remote configs for tracking: %s", _trackingRemoteConfigsJson.dump(JSON_PRINT_INDENT).c_str());
logging::GALogger::i("Remote configs ready with %zu configurations", _gameRemoteConfigsJson.size());
}

void GAState::populateConfigurations(json& sdkConfig)
{
std::lock_guard<std::recursive_mutex> guard(_mtx);
_configurations = {};

json _tempRemoteConfigsJson = {};

try
{
Expand All @@ -933,16 +957,18 @@ namespace gameanalytics

if (!key.empty() && configuration.contains("value") && client_ts_adjusted > start_ts && client_ts_adjusted < end_ts)
{
_configurations[key] = configuration;
_tempRemoteConfigsJson[key] = configuration;
logging::GALogger::d("configuration added: %s", configuration.dump(JSON_PRINT_INDENT).c_str());
}
}
}
}

buildRemoteConfigsJsons(_tempRemoteConfigsJson);

_remoteConfigsIsReady = true;

std::string const configStr = _configurations.dump();
std::string const configStr = _gameRemoteConfigsJson.dump();
for (auto& listener : _remoteConfigsListeners)
{
listener->onRemoteConfigsUpdated(configStr);
Expand Down Expand Up @@ -1160,18 +1186,7 @@ namespace gameanalytics

json GAState::getRemoteConfigAnnotations()
{
json configs;
for(json& obj : _configurations)
{
json cfg;
cfg["vsn"] = utilities::getOptionalValue<int>(obj, "vsn", 0);
cfg["key"] = utilities::getOptionalValue<std::string>(obj, "key", "");
cfg["id"] = utilities::getOptionalValue<std::string>(obj, "id", "");

configs.push_back(cfg);
}

return configs;
return _trackingRemoteConfigsJson;
}
}
}
10 changes: 7 additions & 3 deletions source/gameanalytics/GAState.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ namespace gameanalytics
inline static T getRemoteConfigsValue(std::string const& key, T const& defaultValue)
{
std::lock_guard<std::recursive_mutex> lg(getInstance()._mtx);
if(getInstance()._configurations.contains(key))
if(getInstance()._gameRemoteConfigsJson.contains(key))
{
json& config = getInstance()._configurations[key];
json& config = getInstance()._gameRemoteConfigsJson[key];
T value = utilities::getOptionalValue<T>(config, "value", defaultValue);
return value;
}
Expand Down Expand Up @@ -210,6 +210,8 @@ namespace gameanalytics

void addErrorEvent(EGAErrorSeverity severity, std::string const& message);

void buildRemoteConfigsJsons(const json& remoteCfgs);

threading::GAThreading _gaThread;
events::GAEvents _gaEvents;
device::GADevice _gaDevice;
Expand Down Expand Up @@ -271,7 +273,9 @@ namespace gameanalytics

bool _enableIdTracking = true;

json _configurations;
json _gameRemoteConfigsJson;
json _trackingRemoteConfigsJson;

bool _remoteConfigsIsReady;
std::vector<std::shared_ptr<IRemoteConfigsListener>> _remoteConfigsListeners;
std::recursive_mutex _mtx;
Expand Down
Loading