JAL-4001 start of GA4 client class
authorBen Soares <b.soares@dundee.ac.uk>
Mon, 5 Jun 2023 10:30:39 +0000 (11:30 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Mon, 5 Jun 2023 10:30:39 +0000 (11:30 +0100)
src/jalview/analytics/GoogleAnalytics4.java [new file with mode: 0644]

diff --git a/src/jalview/analytics/GoogleAnalytics4.java b/src/jalview/analytics/GoogleAnalytics4.java
new file mode 100644 (file)
index 0000000..6b9f03a
--- /dev/null
@@ -0,0 +1,78 @@
+package jalview.analytics;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+public class GoogleAnalytics4 {
+       private static final String JALVIEW_ID = "Jalview Desktop";
+       private static final String SESSION_ID = new Random().toString();
+       private static final String MEASUREMENT_ID = "G-6TMPHMXEQ0";
+       private static final String BASE_URL = "https://www.google-analytics.com/mp/collect";
+
+       private List<Map.Entry<String, String>> queryStringValues;
+       private List<Map.Entry<String, Object>> jsonValues;
+       private List<Map.Entry<String, String>> cookies;
+
+       private void addToJson(String key, List<String> values) {
+       }
+
+       private void addToJson(String key, String value) {
+       }
+
+       private void addToJson(String key, int value) {
+       }
+
+       private void addToJson(String key, boolean value) {
+       }
+
+       private void addToJson(String key, Object[] array) {
+       }
+
+       private void addQueryStringValue(String key, String value) {
+       }
+
+       private void reset() {
+               jsonValues = new ArrayList<>();
+               queryStringValues = new ArrayList<>();
+               cookies = new ArrayList<>();
+       }
+
+       private String buildJson() {
+               StringBuilder sb = new StringBuilder();
+               int indent = 0;
+               sb.append("{");
+               indent++;
+
+               sb.append("}");
+               return sb.toString();
+       }
+
+       private void addJsonObject(StringBuilder sb, int indent, String key, Object value) {
+               indent(sb, indent);
+               sb.append('"').append(key).append('"');
+               sb.append(": ");
+               if (List.class.equals(value.getClass())) {
+                       sb.append('\n');
+               }
+               addJsonValue(sb, indent, value);
+               sb.append(",\n");
+       }
+
+       private void addJsonValue(StringBuilder sb, int indent, Object value) {
+               if (value == null) {
+                       return;
+               }
+               Class c = value.getClass();
+               if (String.class.equals(c)) {
+               } else if (Integer.class.equals(c)) {
+               } else if (Boolean.class.equals(c)) {
+               }
+               sb.append(value);
+       }
+
+       private void indent(StringBuilder sb, int indent) {
+               sb.append("  ".repeat(indent));
+       }
+}