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");


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.

15 thoughts on “Google Analytics for Java applications

  1. 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. Using JGoogleAnalytics should be legal anywhere, where using Google Analytics is legal. I don’t see any real dfference between using the two.

  3. 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.

  4. 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. 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.

  6. Hi Siddique. I was looking for a way to track my batch processes using Google Analytics, and I found this open source project. Thanks! I’m going to try it now. Last update to JGoogleAnalytics is 2008. Does it still work now?

  7. Hi Siddique. I’ve just integrated the project jgoogleanalytics into a Matlab GUI for tracking the use as a web page and it appears to work perfectly fine. Thank you a lot for that !

  8. Is there a way to set a GA Variable on the tracker? The original GA lets you set a single variable, which I believe has been extended to many variables. I am just looking to set the single variable though.

    For example, I use GAForFlash ( to send GA events in flex and it provides a “setVar(String var)” method on the tracker object.


  9. To answer my own question…

    I wrote an implementation of URLBuildingStrategy that looks almost identical to the provided GoogleAnalytics_v1_URLBuildingStrategy, except that it takes a variable in the constructor and sets that in the URL building portion.

    Right at the end of that method I replaced..


    Then I stick my builder in the tracker before calling the async tracking method.

    Thanks! Ryan

  10. Good work.

    But I am not sure how reliably this can be used for two major reason:
    1. Lack of documentation or sample java source code which shows how its being done.
    2. Google has recently started deprecating one API after the other. Who knows when they may bring down Google Analytics API also??


  11. I was just wondering if anyone has been able to get this to work without actually having a domain. I have set up a Google Analytics account and tried the sample code with my tracking ID and nothing show up even after several hours. I did noticed that my Google Analytics account says its not set up because there is tracing code on the made up domain I filled in.

    Any help would be very much appreciated.


  12. I am not sure if it works without an “actual domain”. In other words some random non-existing domain. I would suggest using some existing domain for the setup like.. your company domain or any URL resource like or whatever that belong to you or own.

    Hope it helps.

  13. In LibraryFinder applicatin where you set the focus point? And please let me know how to set focus point, where to use it?

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>