| 115 | } |
| 116 | |
| 117 | void EditorAnalytics::StartSession() |
| 118 | { |
| 119 | ScopeLock lock(Locker); |
| 120 | if (::IsSessionActive) |
| 121 | return; |
| 122 | PROFILE_CPU(); |
| 123 | |
| 124 | // Prepare client metadata |
| 125 | ClientId = Platform::GetUniqueDeviceId().ToString(Guid::FormatType::N).ToStringAnsi(); |
| 126 | StringAnsi ProjectName = Editor::Project->Name.ToStringAnsi(); |
| 127 | const auto desktopSize = Platform::GetDesktopSize(); |
| 128 | StringAnsi ScreenResolution = StringAnsi::Format("{0}x{1}", (int32)desktopSize.X, (int32)desktopSize.Y); |
| 129 | const auto memoryStats = Platform::GetMemoryStats(); |
| 130 | StringAnsi Memory = StringAnsi::Format("{0} GB", (int32)(memoryStats.TotalPhysicalMemory / 1024 / 1024 / 1000)); |
| 131 | StringAnsi UserLocale = Platform::GetUserLocaleName().ToStringAnsi(); |
| 132 | StringAnsi GPU; |
| 133 | if (GPUDevice::Instance && GPUDevice::Instance->GetState() == GPUDevice::DeviceState::Ready) |
| 134 | GPU = StringAsANSI<>(GPUDevice::Instance->GetAdapter()->GetDescription().GetText()).Get(); |
| 135 | SessionStartTime = DateTime::Now(); |
| 136 | StringAnsiView EngineVersion = FLAXENGINE_VERSION_TEXT; |
| 137 | #if PLATFORM_WINDOWS |
| 138 | StringAnsiView PlatformName = "Windows"; |
| 139 | #elif PLATFORM_LINUX |
| 140 | StringAnsiView PlatformName = "Linux"; |
| 141 | #elif PLATFORM_MAC |
| 142 | StringAnsiView PlatformName = "Mac"; |
| 143 | #else |
| 144 | #error "Unknown platform" |
| 145 | #endif |
| 146 | |
| 147 | // Initialize HTTP |
| 148 | Url = StringAnsi::Format("{0}?measurement_id={1}&api_secret={2}", GA_URL, GA_MEASUREMENT_ID, GA_API_SECRET); |
| 149 | curl_global_init(CURL_GLOBAL_ALL); |
| 150 | CurlHttpHeadersList = curl_slist_append(nullptr, "Content-Type: application/json"); |
| 151 | ::IsSessionActive = true; |
| 152 | |
| 153 | // Start session |
| 154 | { |
| 155 | const Pair<const char*, const char*> params[1] = { { "Project", ProjectName.Get() }, }; |
| 156 | SendEvent("Session", ToSpan(params, ARRAY_COUNT(params))); |
| 157 | } |
| 158 | |
| 159 | // Report telemetry stats |
| 160 | #define SEND_TELEMETRY(name, value) \ |
| 161 | if (value.HasChars()) \ |
| 162 | { \ |
| 163 | const Pair<const char*, const char*> params[1] = { { name, value.Get() } }; \ |
| 164 | SendEvent("Telemetry", ToSpan(params, ARRAY_COUNT(params))); \ |
| 165 | } |
| 166 | SEND_TELEMETRY("Platform", PlatformName); |
| 167 | SEND_TELEMETRY("GPU", GPU); |
| 168 | SEND_TELEMETRY("Memory", Memory); |
| 169 | SEND_TELEMETRY("Locale", UserLocale); |
| 170 | SEND_TELEMETRY("Screen", ScreenResolution); |
| 171 | SEND_TELEMETRY("Version", EngineVersion); |
| 172 | #undef SEND_TELEMETRY |
| 173 | |
| 174 | // Bind events |
nothing calls this directly
no test coverage detected