first experiment with GA application use tracking
[jalview.git] / src / jalview / bin / Cache.java
index 9fe0009..dad7326 100755 (executable)
@@ -24,6 +24,9 @@ import java.util.*;
 import org.apache.log4j.*;
 import org.biojava.dasobert.dasregistry.Das1Source;
 
+import com.boxysystems.jgoogleanalytics.FocusPoint;
+import com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker;
+
 /**
  * Stores and retrieves Jalview Application Properties Lists and fields within
  * list entries are separated by '|' symbols unless otherwise stated (|) clauses
@@ -527,5 +530,37 @@ public class Cache
     }
     return localSources;
   }
-
+  
+  public static JGoogleAnalyticsTracker tracker=null;
+  
+  public static void initGoogleTracker()
+  {
+    if (tracker==null)
+    {
+      String vrs="No Version Accessible";
+      try {
+    //Google analytics tracking code for Library Finder
+      tracker = new JGoogleAnalyticsTracker("Jalview Desktop",
+              (vrs=jalview.bin.Cache.getProperty("VERSION")+"_"+jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")),
+              "UA-9060947-1");
+      tracker.trackAsynchronously(new FocusPoint("Application Started."));
+    } catch (RuntimeException e)
+    {
+      if (log!=null) {
+        log.debug("Caught runtime exception in googletracker init:",e);
+      } 
+      // quietly return.
+    }
+      catch (Exception e)
+    {
+        // unexpected error
+        if (log!=null)
+        {
+          log.warn("Failed to initialise GoogleTracker for Jalview Desktop with version "+vrs,e); 
+        } else {
+          log.warn("Failed to initialise GoogleTracker for Jalview Desktop with version "+vrs,e);
+        }
+    }
+    }
+  }
 }