GA can be used for this, although since it is a free tool, it is slightly limited compared to other tools. Other tools include Yahoo Web Analytics (YWA), Omniture SiteCatalyst, and Webtrends.
Most tracking tools out there have the ability to do custom communication and event tracking. Basically, what you need to do is find the right code snippet for custom link tracking and put it in a wrapper function that will be executed in the onclick event (or add an event listener, etc.).
The first thing you want to do is decide which "events" you want to have for the widget (s). You mentioned counting widgets. This is quite simple to do: just place a piece of custom code on the page on which the widget is embedded.
But besides this ... presses any combination of buttons as one event? Does each button mean a different event? etc. Also, are there any custom values โโthat you want to associate with buttons, for example, a product identifier or description, or something else.
Another important thing to ask yourself when you decide what you want to track is "How effective is this data?" You canโt keep track of very little, but there are many things that are not very useful for making real business decisions.
For example, it looks like you want to try to measure user interaction with widgets. Iโm sure the idea is to find out how useful, attractive, etc ... they are for people, so you can figure out whether to develop them or throw money at them or throw them. Fair. But just remember to make events focused. Knowing how many times a user clicked a button is not very useful, because by itself it is not very effective. Knowing how many times people have completed a process or step, etc., is more effective.
Once you have made a list of what you want to track and when, then you can start creating your own code.
With GA, there are 2 main ways to track events and indicators: through steps / goals and through user variables. The way you set up steps / goals with GA is to map GA to the URL of the page. For example, if you have a newsletter subscription registration form, there may be signup.html on the form page, and signup_confirmation.html on the confirmation page. Then you set the target in the GA interface. The target will match signup_confirmation.html, and you could try to find signup.html. You can then see how many people viewed your form and completed it, or abandoned it.
You can use the same tracking method with events by clicking on the virtual page view on GA.
Here is an article that details how to click on the view virtual page:
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55521
But basically, whenever an event occurs (e.g. widget view, button click, etc., you should execute the following javascript:
pageTracker._trackPageview (virtual URL here);
The main thing to note about this method is that you can organize / categorize / provide a hierarchy to your data by passing delimited values. This will help you collect data for different widgets / sites.
The second way to record events is with user variables. Using custom variables during events provides many opportunities for reporting and flexibility. Here is a link to use them:
http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html