Google Analytics is a great marketing tool that can be used in order to get detailed information about the users of your web sites and their navigation patterns. The standard approach is to track page visits (where statistics can be aggregated by visited URLs), but there are times where you would want a higher granularity of which actions your users do, where these can’t be tracked exclusively by URL.
_trackEvent. A sample usage would be:
The parameters to track event (category, event and label) can be used within Analytics to obtain three levels of statistical aggregation of data. E.g. in our case we may use categories for
subscription… Within document we have events for
add comment… As a label to document operations we may assign a user id, a document type, or however we wish the document events to be labelled for later analysis.
Integrating event tracking with Struts actions
The approach we used in order to be able to track events from within Struts can be summarised in the following steps:
- An object associated with the user session keeps a list of generated events
- We include this custom tag as part of the default site template, so that it appears in all pages