Google Analytics _trackEvent not working

假装没事ソ 提交于 2019-12-13 18:01:13

问题


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>

回答1:


Check under the real-time reports is it showing up there. Remember that it can take up to 24 hours for the data to show up in the standard reports.

Your code should look something like this:

<a href='#' onclick="ga('send', 'event', 'button', 'click', 'test', 4);"> Test Event</a>

This page should help you understand how it should look Event Tracking - Web Tracking (analytics.js)

Add a comment if this doesn't help. See if i can help you get it working how you want.




回答2:


It's not recording the event because you are sending them to another page before the event tracking in Google Analytics has a chance to record.

See Track outbound links

This will show you how to set up a function that allows the event tracking to be sent to GA before the user is sent to another page.




回答3:


There's two possible reasons why this might not work: (1) Code has a bug in it, or (2) Its not actually sending to GA (3) Goals not set up

I can't see anything wrong with it, so I'm going to skip over number 1.

You may want to get a GA debugger and work from there to see what is happening. If you have an analytics blocker, I recommend turning it off. Also, the data won't appear immediately. Google has the little habit of filtering data before it is presented to you.

For your goals, make sure you are actually capturing the information. I've made this mistake before. I set up the event tracking, wait for the events... and they never come. You'll have to set up a goal in GA to listen for this.



来源:https://stackoverflow.com/questions/21808138/google-analytics-trackevent-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!