Google Analytics’s Event Tracking is a powerful way to gain a deeper understanding of what is happening on your website. With event tracking, you can record each click, keypress or mouse move; it becomes easy to find out which fields are being filled or skipped on a form, or which thumbnails are being hovered.
I came across one sneaky gotcha this morning, though. I wanted to track the number that was displayed in a field at the point the user clicked on an “Add” button:
_gaq.push([ '_trackEvent', 'Page Updates', 'Plus button clicked', parseInt($('#count').text()) ]);
On reviewing the data in GA, however, none of the clicks were being captured.
It turns out that Google will not record the event if the fourth parameter is of type Number. The simple fix was to make it a String type:
_gaq.push([ '_trackEvent', 'Page Updates', 'Plus button clicked', parseInt($('#count').text()).toString() ]);