1

I am trying to track each menu on the website using _trackEvent of Google analytic. So far Analytic is working fine but Event Tracking is not working.

Below is the code i am using

// Analytics
    (function (i, s, o, g, r, a, m) {
        i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
            (i[r].q = i[r].q || []).push(arguments)
        }, i[r].l = 1 * new Date(); a = s.createElement(o),
  m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

    ga('create', 'UA-481xxxxx-1', 'ABC.com');
    ga('send', 'pageview');

and in html code i am using is like this.

<li>
<a onclick="_gaq.push(['_trackEvent', 'Top_Menu', 'contact-details']);" href="en/10/contact-details">CONTACT</a>
</li>

For some reason it is not tracking my events.

Am i using wrong version of analytic.

UPDATE: Even this is not working

<li> 
<a onclick="ga('send', 'event', { 'eventCategory': 'Navigation', 'eventAction': 'Click', 'eventLabel': 'about-the-group});" href="en/about/about-us">ABOUT US</a>
</li>
Learning
  • 19,469
  • 39
  • 180
  • 373
  • 2
    You are mixing Universal Analytics (new) and asychnronous analytics (old). There is no _gaq array (and hence no _gaq.push) in Universal Analytics. See here for more info:http://stackoverflow.com/questions/18696998/ga-or-gaq-push-for-google-analytics-event-tracking – Eike Pierstorff Feb 16 '14 at 09:43
  • @EikePierstorff, I had my doubts regarding same... for the same reason i had mentioned `Am i using wrong version of analytic.` I would appreciate if you can show me an example how should i call `ga()` from an as a simple function `onClick="ga(...)"` – Learning Feb 16 '14 at 09:58
  • ga('send', 'event', 'category', 'action', 'label', value, non-interaction); ( where value is an (optional) integer and non-interaction an (optional) boolean). – Eike Pierstorff Feb 16 '14 at 10:06
  • Is this okay ` Menu ` if this is right then it is still not tracking event for some reason. – Learning Feb 16 '14 at 10:06
  • Lose the Backslashes, they will cause javascript errors. And if you pass a javascript variable (SEOName) you don't need to bother with quotation marks. Otherwise that looks okay. – Eike Pierstorff Feb 16 '14 at 10:24
  • I am not able to make it work this is my final html rendered as outpu `
  • ABOUT US
  • ` – Learning Feb 16 '14 at 10:45