Google Analytics事件跟踪无效

时间:2014-01-25 11:51:42

标签: events analytics

对于我的生活,我无法让谷歌事件跟踪工作。我正在尝试跟踪我网站中某些图片的点击次数。我等了好几天,我尝试过使用firebug和google chrome调试器,没有运气。如果有人能告诉我我做错了什么,我真的非常感激不尽。我的代码如下。非常感谢。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Hug Addicts | A variety of hug t-shirts.</title>
<!-- js -->
<script type="text/javascript">
var subMenus = new Array();
    subMenus[0] = "shirt1";
    subMenus[1] = "shirt2";
    subMenus[2] = "shirt3";
    subMenus[3] = "shirt4";
    subMenus[4] = "shirt5";
    subMenus[5] = "shirt6";
    subMenus[6] = "shirt7";
    subMenus[7] = "shirt8";
    subMenus[8] = "shirt9";
    subMenus[9] = "shirt10";
    function revealshirt(id)
    {
    for (var i = 0; i < subMenus.length; i++)
    {
    document.getElementById(subMenus[i]).style.background = "transparent";
    } 
    document.getElementById(id).style.background = "#e0e0e0";
    }
    </script>
<!-- end js -->

<!-- Style Sheet -->
<link href="_css/reset.css" media="screen" type="text/css" rel="stylesheet" />
<link href="_css/layout.css" media="screen" type="text/css" rel="stylesheet" />
<!-- End Style Sheet -->

<meta name="verify-v1" content="G4CQZIfIEXbhZZcpfWDJnAJe+R4lTGtVhzYsKhcRzS4=" />

<!-- Google Analytics -->
<script>
  (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-47147009-1', 'hugaddict.com');
  ga('send', 'pageview');
      var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-47147009-1']);
    _gaq.push(['_trackPageview']);
</script>
<!-- Google Analytics -->
</head>

<body id="homeid">
  <div id="wrapper">
    <div id="container">
      <div id="container_inner">        
    <div id="header">
     <h1><a href="index.html" title="" target="">Header</a></h1>        
                <div id="navigation">
                    <ul id="nav">
    <li id="prints">
        <a href="index.html" onClick="_gaq.push(['_trackEvent', 'Click', 'TestTees']);" title="" target="">Tees</a>
    </li>
    <li id="about">
        <a href="aboutus.html" onClick="_gaq.push(['_trackEvent', 'Click', 'TestAbout']);" title="" target="">About</a>
    </li>
    <li id="contact">
        <a href="contact.html" onClick="_gaq.push(['_trackEvent', 'Click', 'TestContact']);" title="" target="">Contact</a>
    </li>

</ul>

                </div>
                </div><!-- header -->       
                <div id="main">
                    <div id="notice">Hello, my name is . . . and I am an addict.</div>
                    <div id="mac_nav">
                        <ul>
                        <li id="shirt1">
                            <a href="shirts/clean_huggie.html" title="" target="shirts" onmousedown="revealshirt('shirt1'); return false;">Link</a>
                        </li>
                        <li id="shirt2">
                            <a href="shirts/recreational_huggie.html" onClick="_gaq.push(['_trackEvent', 'Click2', 'MaleRecreationalHugs']);" title="" target="shirts" onmousedown="revealshirt('shirt2'); return false;">Link</a>
                        </li>
                        <li id="shirt3">
                            <a href="shirts/hardcore_huggie.html" onClick="_gaq.push(['_trackEvent', 'Click1', 'MaleHardcoreHugs']);" title="" target="shirts" onmousedown="revealshirt('shirt3'); return false;">Link</a>

                        </li>
                        <li id="shirt4">
                            <a href="shirts/pill_huggie.html" onClick="_gaq.push(['_trackEvent', 'Click', 'MenPillHugs']);" title="" target="shirts" onmousedown="revealshirt('shirt3'); return false;">Link</a>
                        </li>
                        <li id="shirt5">
                            <a href="shirts/Marker_Felt.html" title="" target="shirts" onmousedown="revealshirt('shirt5'); return false;">Link</a>
                        </li>
                    </div>

                    <div id="content">
                        <iframe src="shirts/dealing_huggie.html" width="520px" height="600px" name="shirts" scrolling="no"></iframe>
                    </div>

                    <div id="pc_nav">
                        <ul>

                        <li id="shirt6">
                            <a href="shirts/dealing_huggie.html" onClick="_gaq.push(['_trackEvent', 'Click', 'FemaleHugDealer']);" title="" target="shirts" onmousedown="revealshirt('shirt6'); return false;">Link</a>
                        </li>

                        <li id="shirt7">
                            <a href="shirts/performance_huggie.html" onClick="_gaq.push(['_trackEvent', 'Click', 'FemalePerfromanceHugs']);" title="" target="shirts" onmousedown="revealshirt('shirt7'); return false;">Link</a>
                        </li>
                        <li id="shirt8">
                            <a href="shirts/smuggling_huggie.html" onClick="_gaq.push(['_trackEvent', 'Click', 'FemaleHugSmuggler']);" title="" target="shirts" onmousedown="revealshirt('shirt8'); return false;">Link</a>
                        </li>
                        <li id="shirt9">
                            <a href="shirts/addicted_huggie.html" onClick="_gaq.push(['_trackEvent', 'Click', 'FemaleHugAddicted']);" title="" target="shirts" onmousedown="revealshirt('shirt8'); return false;">Link</a>

                        </li>
                        <li id="shirt10">
                            <a href="shirts/Symbol.html" title="" target="shirts" onmousedown="revealshirt('shirt10'); return false;">Link</a>
                        </li>
                        </ul>                   
                    </div>      
                </div>

                <div id="footer">
                </div>

            </div>
        </div>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:4)

您使用的是相对较新的通用分析跟踪代码(analytics.js),但事件跟踪代码适用于较旧的分析版本(ga.js)。使用旧版本的分析代码或使用适当的事件跟踪代码进行通用分析:

而不是:

onClick="_gaq.push(['_trackEvent', 'Click', 'FemaleHugAddicted']);"

使用(您可以为类别/操作/标签字段使用空格):

onclick="ga('send', 'event', 'Click', 'Female Hug Addicted', 'optional label name');"

您可以在这里阅读更多内容: https://developers.google.com/analytics/devguides/collection/analyticsjs/events