JAL-4001 Add a _geo=1 to query string and JSON. Add a headless flag to path and...
authorBen Soares <b.soares@dundee.ac.uk>
Fri, 16 Jun 2023 14:22:52 +0000 (15:22 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Fri, 16 Jun 2023 14:22:52 +0000 (15:22 +0100)
src/jalview/analytics/GoogleAnalytics4.java
src/jalview/bin/Cache.java
src/jalview/bin/Jalview.java

index ba8a920..7119828 100644 (file)
@@ -155,7 +155,9 @@ public class GoogleAnalytics4
     addEvent(eventName, params);
     addQueryStringValue("measurement_id", MEASUREMENT_ID);
     addQueryStringValue("api_secret", API_SECRET);
+    addQueryStringValue("_geo", "1");
     addJsonValue("client_id", CLIENT_ID);
+    addJsonValue("_geo", 1);
     addJsonValues("events", Event.toObjectList(events));
     StringBuilder urlSb = new StringBuilder();
     urlSb.append(BASE_URL);
index 8015cd5..e92fc75 100755 (executable)
@@ -43,6 +43,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
@@ -958,6 +959,11 @@ public class Cache
    */
   public static void initGoogleTracker()
   {
+    initGoogleTracker(false);
+  }
+
+  public static void initGoogleTracker(boolean headless)
+  {
     GoogleAnalytics4.setEnabled(true);
 
     String appName = ChannelProperties.getProperty("app_name") + " Desktop";
@@ -973,8 +979,15 @@ public class Cache
     } catch (UnsupportedEncodingException e)
     {
     */
-    path = ("/" + String.join("/", appName, version, APPLICATION_STARTED))
-            .replace(' ', '+');
+    List<String> pathParts = new ArrayList<>();
+    pathParts.add(appName);
+    pathParts.add(version);
+    pathParts.add(APPLICATION_STARTED);
+    if (headless)
+    {
+      pathParts.add("headless");
+    }
+    path = ("/" + String.join("/", pathParts)).replace(' ', '+');
     /*
     }
     */
@@ -983,12 +996,22 @@ public class Cache
     // This will add a page_view similar to the old UA analytics.
     // We probably want to get rid of this once the application_launch event
     // is being processed properly.
-    ga4.sendAnalytics("page_view", "page_location", path, "page_title",
-            APPLICATION_STARTED);
+    String[] params;
+    if (headless)
+    {
+      params = new String[] { "page_location", path, "page_title",
+          APPLICATION_STARTED, "headless", "true" };
+    }
+    else
+    {
+      params = new String[] { "page_location", path, "page_title",
+          APPLICATION_STARTED };
+    }
+    ga4.sendAnalytics("page_view", params);
 
     // This will send a new "application_launch" event with parameters
     // including the old-style "path", the channel name and version
-    ga4.sendAnalytics("application_launch", true, "page_location", path);
+    ga4.sendAnalytics("application_launch", true, params);
   }
 
   private static final String APPLICATION_STARTED = "Application Started.";
index 3a733f3..1f86926 100755 (executable)
@@ -810,6 +810,7 @@ public class Jalview
     // Run Commands from cli
     cmds = new Commands(argparser, headlessArg);
     boolean commandsSuccess = cmds.argsWereParsed();
+
     if (commandsSuccess)
     {
       if (headlessArg)
@@ -822,6 +823,11 @@ public class Jalview
         }
         else
         {
+          // record usage stats if in headless mode
+          if (Cache.getDefault("USAGESTATS", false))
+          {
+            Cache.initGoogleTracker(headlessArg);
+          }
           Jalview.exit("Successfully completed commands in headless mode",
                   0);
         }