private static GoogleAnalytics4 instance = null;
- private static final String appName;
-
- private static final String version;
+ private static final Map<String, String> defaultParams;
static
{
- appName = ChannelProperties.getProperty("app_name") + " Desktop";
- version = Cache.getProperty("VERSION") + "_"
- + Cache.getDefault("BUILD_DATE", "unknown");
+ defaultParams = new HashMap<>();
+ defaultParams.put("app_name",
+ ChannelProperties.getProperty("app_name") + " Desktop");
+ defaultParams.put("version", Cache.getProperty("VERSION"));
+ defaultParams.put("build_date",
+ Cache.getDefault("BUILD_DATE", "unknown"));
+ defaultParams.put("java_version", System.getProperty("java.version"));
+ String val = System.getProperty("sys.install4jVersion");
+ if (val != null)
+ {
+ defaultParams.put("install4j_version", val);
+ }
+ val = System.getProperty("installer_template_version");
+ if (val != null)
+ {
+ defaultParams.put("install4j_template_version", val);
+ }
+ val = System.getProperty("launcher_version");
+ if (val != null)
+ {
+ defaultParams.put("launcher_version", val);
+ }
+ defaultParams.put("java_arch",
+ System.getProperty("os.arch") + " "
+ + System.getProperty("os.name") + " "
+ + System.getProperty("os.version"));
}
private GoogleAnalytics4()
ENABLED = b;
}
+ /**
+ * The simplest way to send an analytic event.
+ *
+ * @param eventName
+ * The event name. To emulate a webpage view use "page_view" and set
+ * a "page_location" parameter. See
+ * https://developers.google.com/analytics/devguides/collection/ga4/events?client_type=gtag
+ * @param paramsStrings
+ * Optional multiple Strings in key, value pairs (there should be an
+ * even number of paramsStrings) to be set as parameters of the
+ * event. To emulate a webpage view use "page_location" as the URL in
+ * a "page_view" event.
+ */
public void sendAnalytics(String eventName, String... paramsStrings)
{
// clear out old lists
Map<String, String> params = new HashMap<>();
// add these to all events from this application instance
- params.put("app_name", appName);
- params.put("version", version);
+ params.putAll(defaultParams);
- // can be overwritten by passed in params
+ // add (and overwrite with) the passed in params
if (paramsStrings != null && paramsStrings.length > 0)
{
if (paramsStrings.length % 2 != 0)