As you may or may not be aware google analytics is one of the free service provided by Google for website owners. It would allow website owners to track the usage data and perform usage & trend analysis on websites. Whether you have a personal blog, social networking portal, corporate website or just a family website, you will be able to track the information about the visitors and what part of the website they use more etc. So, it would help the webmasters to find their target audience and identify the areas for improvements.

Conventionally, google analytics is used only for tracking websites and web portals. As a open-source contributor I often wonder, is there a way to track the usage on non web-based applications. I was curious to know about my users, what part of the tool they use more or even less. Hence, the genesis of JGoogleAnalytics. It's a light-weight, unobtrusive utility used for tracking usage data on Java applications thro Google analytics. If you are a plugin(IntelliJ, Eclipse, Netbeans) developer or own a full blown Java web portal, you will be able to track the usage data.

As a proof of concept, I have used this tool in Library Finder - IntelliJ plugin. I am capturing events like plugin load and some of the user actions. Following is the sample code to track the usage data. FocusPoint is a logical point of focus in the application. It can be events like application/module load, user actions, error events etc.

   //Google analytics tracking code for Library Finder
  JGoogleAnalyticsTracker tracker = new JGoogleAnalyticsTracker("Library Finder","1.3.2","UA-2184000-1"); 

  FocusPoint focusPoint = new FocusPoint("PluginLoad");

  tracker.trackAsynchronously(focusPoint);
  

There are two ways you can capture the usage data. You can track them either Synchronously or Asynchronously. Please note that you may always want to use the Async approach unless otherwise it's required or if you are ready to sacrifice some performance hit on the actual application. Tracking asynchronously is the ideal way as it will be running on a low-priority thread.

Here is the google analytics screenshot showing the usage on Library Finder.

Please let me know if you have any suggestions, comments or critiques.

5 Responses to “Google Analytics for Java applications”

  1. Alex Says:
    It's an interesting idea, but I'm not sure a user would appreciate beeing tracked without their knowledge... I'm not sure what the rules are in your part of the world, but where I live, this would most likely be illegal.
  2. Siddique Says:
    Google Analytics does not track any user sensitive or privacy related data. It tracks the IP address & information about the area/page of the website being visited. There are millions of websites already using it and I don't see anything illegal about that. JGoogleAnalytics is a very light-weight emulation of Google Analytics javascript code. It makes a HTTP request to the google-analytics server with the application tracking code, hostname and focus point(some logic point of interest in the app) data. It doesn't send anything more than that. It's a open-source tool. So, feel free to take a look at the code and make any comments/complaints/suggestions you may have.
  3. Psyho Says:
    Using JGoogleAnalytics should be legal anywhere, where using Google Analytics is legal. I don't see any real dfference between using the two.
  4. Kyle Says:
    Hi there, I've been using your code for a little while now, but I've noticed something odd. I may just be ignorant, but when I check my analytics account, the visitors to my app never shows more than one. I have tested this over numerous days, with different machines on different networks, but it's always showing one visitor per day, regardless of page hits. I'm just wondering if this is a known issue, or if I've just configured things inappropriately. Thanks!
  5. Siddique Says:
    Hi Kyle, I see your point. For some reason, the usages are not tracked at the top website level. But, if you look at the Content -> Top Content, the no. of page views can be translated to the no. of hits to the FocusPoint. I'll investigate if there is an option to collect the FocusPoint usage metrics counted at the top site level and let you know if I find anything. Please let me know if you have any further questions, comments or concerns.

Sorry, comments are closed for this article.