user3234971
user3234971

Reputation: 1

Google Analytics Event Tracking Won't Work

For the life of me, I can't get google event tracking to work. I'm trying to track clicks on certain images in my site. I've waited a number of days, I've tried using firebug and google chrome debugger with no luck. I would be really, really indebted if someone could tell me what I'm doing wrong. My code is below. Thank you so much.

<!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>

Upvotes: 0

Views: 3080

Answers (1)

Roie
Roie

Reputation: 326

You are using the relatively new universal analytics tracking code (analytics.js) but the event tracking code is for the older analytics version (ga.js). Either use the older version of analytics code or use the proper event tracking code for universal analytics:

instead of:

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

Use (you can use spaces for the category / action / label fields):

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

You can read more here: https://developers.google.com/analytics/devguides/collection/analyticsjs/events

Upvotes: 4

Related Questions