+package compbio.ws.server;\r
+\r
+import java.net.InetAddress;\r
+import java.net.UnknownHostException;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.engine.conf.PropertyHelperManager;\r
+import compbio.stat.ga.AnalyticsConfigData;\r
+import compbio.stat.ga.GoogleAnalyticsTracker;\r
+import compbio.util.PropertyHelper;\r
+import compbio.util.Util;\r
+import compbio.ws.client.Services;\r
+\r
+public class GAUtils {\r
+\r
+ // MODIFY BEFORE RELEASE!\r
+ final static String VERSION_TYPE = "WAR";\r
+\r
+ private static final Logger log = Logger.getLogger(GAUtils.class);\r
+\r
+ static PropertyHelper PROP_HELPER = PropertyHelperManager\r
+ .getPropertyHelper();\r
+\r
+ private static AnalyticsConfigData config = new AnalyticsConfigData(\r
+ "UA-26161150-1");\r
+\r
+ private static GoogleAnalyticsTracker TRACKER = new GoogleAnalyticsTracker(\r
+ config);\r
+\r
+ public static final boolean IS_GA_ENABLED = isGoogleAnalyticsEnabled();\r
+\r
+ private static String SERVER_ADDRESS = getServerIP();\r
+\r
+ private static boolean isGoogleAnalyticsEnabled() {\r
+ String val = PROP_HELPER.getProperty("enable.ga");\r
+ if (Util.isEmpty(val)) {\r
+ return false;\r
+ }\r
+ val = val.trim();\r
+ if ("yes".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val)) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ private static String getServerIP() {\r
+ String IP = "127.0.0.1";\r
+ if (!anonymizeIP()) {\r
+ try {\r
+ InetAddress localAddrIP = InetAddress.getLocalHost();\r
+ IP = localAddrIP.getCanonicalHostName();\r
+ } catch (UnknownHostException ignored) {\r
+ }\r
+ }\r
+ return IP;\r
+ }\r
+\r
+ private static boolean anonymizeIP() {\r
+ String val = PROP_HELPER.getProperty("anonymize.ip");\r
+ if (Util.isEmpty(val)) {\r
+ return false;\r
+ }\r
+ if ("yes".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val)) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ static void reportUsage(Services service) {\r
+ String service_name = "UNKNOWN";\r
+ if (service == null) {\r
+ log.warn("GA: Services was NULL!");\r
+ } else {\r
+ service_name = service.toString();\r
+ }\r
+ TRACKER.trackPageViewFromReferrer("JABAWS/2.0/" + service_name,\r
+ service_name, "http://www.compbio.dundee.ac.uk",\r
+ SERVER_ADDRESS, VERSION_TYPE);\r
+ TRACKER.resetSession();\r
+ }\r
+}\r