JAL-4001 Added a random id to User-Agent to ensure separate visits recorded in Plausi... task/JAL-4001_Release_2_11_2_Branch_with_Plausible
authorBen Soares <b.soares@dundee.ac.uk>
Fri, 30 Jun 2023 01:40:31 +0000 (02:40 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Fri, 30 Jun 2023 01:40:31 +0000 (02:40 +0100)
src/jalview/analytics/Plausible.java

index 87b23e0..d9d1503 100644 (file)
@@ -19,6 +19,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 
 import jalview.bin.Cache;
 import jalview.bin.Console;
@@ -27,19 +28,20 @@ import jalview.util.HttpUtils;
 
 public class Plausible
 {
-  private static final String USER_AGENT = HttpUtils.getUserAgent(
-          MethodHandles.lookup().lookupClass().getCanonicalName());
+  private static final String USER_AGENT;
 
   private static final String JALVIEW_ID = "Jalview Desktop";
 
   private static final String DOMAIN = "jalview.org";
 
-  private static final String CONFIG_API_BASE_URL = "https://www.jalview.org/services/analytics/config/url";
+  private static final String CONFIG_API_BASE_URL = "https://www.jalview.org/services/config/analytics/url";
 
-  private static final String DEFAULT_API_BASE_URL = "https://plausible.io/api/event";
+  private static final String DEFAULT_API_BASE_URL = "https://analytics.jalview.org/api/event";
 
   private static final String API_BASE_URL;
 
+  private static final String clientId;
+
   public static final String APPLICATION_BASE_URL = "desktop://localhost";
 
   private List<Map.Entry<String, String>> queryStringValues;
@@ -96,6 +98,13 @@ public class Plausible
 
     // ascertain the API_BASE_URL
     API_BASE_URL = getAPIBaseURL();
+
+    // random clientId to make User-Agent unique (to register analytic)
+    clientId = String.format("%08x", new Random().nextInt());
+
+    USER_AGENT = HttpUtils.getUserAgent(
+            MethodHandles.lookup().lookupClass().getCanonicalName() + " "
+                    + clientId);
   }
 
   private Plausible()