I am trying to fire a Google Analytics Event on a simple image rollover. When clicking the image rollover it needs to go to a URL as well as fire the event. The code that I've tried is below. The only thing that doesn't work is the onclick event.
<a onClick="ga('set', 'nonInteraction', true);ga('send', 'event', 'graphic', 'click', 'Example Title Here',1);" href="#">
That property should be 'onclick', and I would actually recommend attaching the event with some javascript.
<a id="ga_btn" href="#">
<script type="text/javascript">
var ga_btn = document.getElementById('ga_btn');
ga_btn.onclick = function () {
ga('set', 'nonInteraction', true);
ga('send', 'event', 'graphic', 'click', 'Example Title Here',1);
}
</script>
I say use javascript because it's easier to maintain; you can just put all of your events in one place. You could just throw them all in a separate file if you want.