JAL-4001 Add a _geo=1 to query string and JSON. Add a headless flag to path and...
[jalview.git] / src / jalview / bin / Cache.java
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.";