-1

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="#">

PeeHaa
  • 71,436
  • 58
  • 190
  • 262

2 Answers2

1

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.

bearoplane
  • 387
  • 1
  • 7
0
<a onClick="_gaq.push(['_trackEvent', 'Graphic', 'Click', 'Example Title Here']);" href="#">
  <img src="Off.jpg" onmouseover="this.src='On.jpg'" onmouseout="this.src='Off.jpg'" />
</a>

Anatomy of event tracking

alexP
  • 3,672
  • 7
  • 27
  • 36