Saturday, November 8, 2008

Tracking Java Versions using Google Analytics

Update: This code does not work as expected (it will only report the newest JRE version). Please see the newer version here.

Ever wonder what Java version your website visitors have installed? Here's how you can leverage Google Analytics to find out:

  1. Locate the Google Analytics script in your HTML page (you must be using the new "ga.js" version). Here is what mine looks like:
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-XXXXX-X");

  2. Insert the following code after that script:
    <script src='http://java.com/js/deployJava.js' type='text/javascript'></script>
    <script type='text/javascript'>
    var jreVersions = deployJava.getJREs();
    if (jreVersions.length==0)
    pageTracker._setVar("Java: none");
    for (var i=0; i<jreVersions.length; ++i)
    pageTracker._setVar("Java: " + jreVersions[i]);

  3. Please note, if you are using Blogger you will need to encode the '<' character as "&lt;". Open up Error Console in your browser to double-check that the script is not generating any errors.
  4. Wait 24 hours for Google to update the report.
  5. View the updated data at Google Analytics -> Visitors -> User Defined.
  6. There are two ways to drill-down based on user-defined values:
    1. Advanced Segments -> New -> Dimensions -> Visitors -> User Defined. For example:
      1. Track users without Java: Matches Exactly: "Java: none"
      2. Track users with Java: Starts With: "Java:" and Does Not Match Exactly: "Java: none"
      3. Track users with Java 1.6: Starts With: "Java: 1.6"
      4. You can then check how many Flash users also had Java installed. Or how many Windows users had Java 1.6 installed. Or the connection speed of Java users.
    2. Visitors -> User Defined -> [Pick One] -> Dimension. For example, you can now click on Java: 1.6.0 -> Dimension -> Browser to find out what browsers visitors with Java 1.6.0 were using.
  7. Publish your results here: http://forums.java.net/jive/thread.jspa?messageID=317425


Unknown said...

Very handy - thanks. I'll be interested to see the results.

mbien said...

thank you for sharing. Shouldn't the tracker only upload the latest or even better, the currently active java version instead of all versions available on the system? AFAIK applets and webstart apps can't choose between versions anyway.

Gili said...


The new Java Plugin allows you to choose a specific Java version: http://java.sun.com/javase/6/webnotes/6u10/plugin2/version-selection/index.html

as does the JNLP specification (java -> version): http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html

mbien said...

thanks, makes sense ;) I thought there would be only a min required version but there are now also version ranges possible.

Unknown said...

This is indeed a very handy tips and tricks.

The questions is how the counting is calculated ? is it per hits/pageviews or pervisit ?

Gili said...


My interpretation of http://code.google.com/apis/analytics/docs/gaJSApi.html#_gat.GA_Tracker_._setVar is that GA collects all information on a pageview basis (such as browser resolution or, in our case Java version). It then aggregates this information to generate per-visit statistics.

The Java version changing between two pageviews is no different from the browser resolution changing between two pageviews. GA will *somehow* aggregate those pageviews into a single visit.

KCWilson said...

this is nice work...

I just request this feature or a similar one be added to Google's product....