Google Analytics lets you to specify up to four arguments when tracking an event: Event Category* (text), Action* (text), Label (text), Value (number), Interaction flag (true/false).
* denotes a mandatory argument.
WARNING! This article applies to an older version of Google Analytics. You may want to upgrade to newer version - see more here.
To track an event you're expected to call _trackEvent function:
This approach is ok if you've got just a couple of buttons, but it gets quite messy if you need to track more. So when faced with this problem, I naturally looked into the available jQuery plugins, but they were either too bloated with features that I didn't need, or required quite elaborate parameter passing.
Wouldn't be great if for every link or a button that you need to track you could do just this:
It's actually easy to do, and you don't need no bandwidth-sucking, cache-polluting plugins for that. Below is a simple piece of script that will wire all elements containing data-ga attribute to truly yours _trackEvent function:
I used pipe character "|" as a separator, but you can change that to your liking.
Subscribe and never miss a new article
If you liked this article and want to get more helpful updates - sign up to my mailing list below. I never spam, period.
Subscribe now and get helpful tips on developing .NET apps - never miss a new article.