Google Analytics: universal js and click tracking

If you use the new (as of October 2013) UA google analytics tracking code, then all your old event tracking onclick tags will not work. If you don’t want to muck around with js files, labeling page items and creating event listeners for each possible event, then this is the correct format to use for an onclick= tag:

 

<a onclick="ga('send', 'event', { 'eventCategory': 'your_own_label_here', 'eventAction': 'your_own_label_here', 'eventLabel': 'your_own_label_here', });" href="http://etcetc.com" > Your link text here </a>

optionally, you can add a value:

<a onclick="ga('send', 'event', { 'eventCategory': 'your_own_label_here', 'eventAction': 'your_own_label_here', 'eventLabel': 'your_own_label_here', 'eventValue': 9 });" href="http://etcetc.com" > Your link text here </a>

note the proper use of double and single quotes, and that the event value is not in quotes.

I hope this saves you time. I had a heck of a time finding clear instructions.

 

Here is how to tell the difference between the old and the new universal code

The old tracking code will contain lines that look like this:

_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);

 

The new universal code will not, instead your tag will be represented in the js like this:

ga('create', 'UA-XXXXXXXX-X', 'mydomain.com');
ga('send', 'pageview');