From: Ben Soares Date: Fri, 16 Jun 2023 14:22:52 +0000 (+0100) Subject: JAL-4001 Add a _geo=1 to query string and JSON. Add a headless flag to path and... X-Git-Tag: Release_2_11_4_0~260^2~18 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=093211ab0209394015e87ba8a467d6ee792b055a;p=jalview.git JAL-4001 Add a _geo=1 to query string and JSON. Add a headless flag to path and JSON, and send analytics in headless mode if USAGESTATS=true. --- diff --git a/src/jalview/analytics/GoogleAnalytics4.java b/src/jalview/analytics/GoogleAnalytics4.java index ba8a920..7119828 100644 --- a/src/jalview/analytics/GoogleAnalytics4.java +++ b/src/jalview/analytics/GoogleAnalytics4.java @@ -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); diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 8015cd5..e92fc75 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -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 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."; diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 3a733f3..1f86926 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -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); }