diff --git a/CHANGELOG.md b/CHANGELOG.md index 4329e0f3..27975727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/source/gameanalytics/GACommon.h b/source/gameanalytics/GACommon.h index e761edb8..37f533c6 100644 --- a/source/gameanalytics/GACommon.h +++ b/source/gameanalytics/GACommon.h @@ -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; diff --git a/source/gameanalytics/GAState.cpp b/source/gameanalytics/GAState.cpp index 01a4c912..ae3ba089 100644 --- a/source/gameanalytics/GAState.cpp +++ b/source/gameanalytics/GAState.cpp @@ -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(); } @@ -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")) { @@ -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 guard(_mtx); - _configurations = {}; + + json _tempRemoteConfigsJson = {}; try { @@ -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); @@ -1160,18 +1186,7 @@ namespace gameanalytics json GAState::getRemoteConfigAnnotations() { - json configs; - for(json& obj : _configurations) - { - json cfg; - cfg["vsn"] = utilities::getOptionalValue(obj, "vsn", 0); - cfg["key"] = utilities::getOptionalValue(obj, "key", ""); - cfg["id"] = utilities::getOptionalValue(obj, "id", ""); - - configs.push_back(cfg); - } - - return configs; + return _trackingRemoteConfigsJson; } } } diff --git a/source/gameanalytics/GAState.h b/source/gameanalytics/GAState.h index b2da9593..346a0b86 100644 --- a/source/gameanalytics/GAState.h +++ b/source/gameanalytics/GAState.h @@ -150,9 +150,9 @@ namespace gameanalytics inline static T getRemoteConfigsValue(std::string const& key, T const& defaultValue) { std::lock_guard 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(config, "value", defaultValue); return value; } @@ -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; @@ -271,7 +273,9 @@ namespace gameanalytics bool _enableIdTracking = true; - json _configurations; + json _gameRemoteConfigsJson; + json _trackingRemoteConfigsJson; + bool _remoteConfigsIsReady; std::vector> _remoteConfigsListeners; std::recursive_mutex _mtx;