fix: run analytics only on version specified in config

This commit is contained in:
Ryan Dowling 2023-07-06 19:36:52 +10:00
parent 8c8a0a42f4
commit cf86c50d60
No known key found for this signature in database
GPG key ID: 5539FCDB88950EFD
2 changed files with 18 additions and 12 deletions

View file

@ -9,5 +9,6 @@ This changelog only contains the changes that are unreleased. For changes for in
### Fixes
- Add missing server_run analytics event
- Run analytics only on version specified in config
### Misc

View file

@ -162,25 +162,30 @@ public final class Analytics {
}
public static void endSession() {
timer.cancel();
if (sessionInitialised) {
timer.cancel();
if (events.size() != 0) {
sendAllStoredEvents(true);
}
if (events.size() != 0) {
sendAllStoredEvents(true);
}
Map<String, Object> body = new HashMap<>();
body.put("userId", App.settings.analyticsClientId);
body.put("sessionId", sessionId);
Map<String, Object> body = new HashMap<>();
body.put("userId", App.settings.analyticsClientId);
body.put("sessionId", sessionId);
try {
CompletableFuture<AnalyticsApiResponse> response = makeApiCall("/session/end", body);
response.get(10, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
try {
CompletableFuture<AnalyticsApiResponse> response = makeApiCall("/session/end", body);
response.get(10, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
}
sessionInitialised = false;
}
}
public static boolean isEnabled() {
if (ConfigManager.getConfigItem("analytics.enabled", false) != true) {
if (!ConfigManager.getConfigItem("analytics.enabledVersion", "None")
.equals(Constants.VERSION.toStringForLogging())) {
return false;
}