0

Ok so it's not really new anymore, but I updated the regular tracking code and event tracking code on my company's super outdated website from gaq to ga, and although the page tracking works fine, the event tracking does not. Here's the page tracking code:

<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-21883696-1', 'auto');
ga('send', 'pageview');

</script>

And a download event:

    <div style="float:left; margin:15px 0 0 7px"> 
    <a href="../checklists/Texas-LLCkit-LawyersAid.pdf" target="_blank" onclick="ga('send', 'event', 'Checklist', 'Download', ‘LLC Book’);">
        <img src="../images2/btn_DL_LLCkit.gif"
        alt="Download the LLC kit checklist"
         />
    </a>
    </div>

And here's a link: http://www.lawyersaidservice.com/company-kits/limited-liability-company-kit.php

What am I doing wrong? Thanks in advance!

K Pat
  • 1
  • Have you checked if the tag fires on click in a debugger? I've used the Google Analytics Debugger Chrome extension to do this, with success. – Catherine Smith Mar 29 '16 at 20:15

1 Answers1

1

If that is your exact code, then you need to change the 'smart' quotes to 'straight' quotes around the event label:

onclick="ga('send', 'event', 'Checklist', 'Download', 'LLC Book');"

Javascript doesn't really like the 'smart' quotes (not really smart in my opinion).

nyuen
  • 8,829
  • 2
  • 21
  • 28
  • This is the exact code (checked against the website) and indeed throws a js error. – Eike Pierstorff Mar 29 '16 at 20:43
  • I meant you spotted the exact error (I am frankly not sure what your comment means, there was nothing amiss with your observation :-) ). – Eike Pierstorff Mar 29 '16 at 20:50
  • :) I did go on the site and saw the exact code, and yet I still managed to say "if this is your exact code...". A "duh" moment. – nyuen Mar 29 '16 at 21:03
  • That makes sense. I'm not getting any js errors on my end though. – K Pat Mar 29 '16 at 22:16
  • If you set your console to receive "all" messages, and if you click on the button you are tracking, then you should see the error message. It would say something like `limited-liability-company-kit.php:211 Uncaught SyntaxError: Unexpected token ILLEGAL`. – nyuen Mar 29 '16 at 22:36
  • I fixed them and a few events have been sent through! However, although this might be premature, normally there would be dozens of events by now, not just 4. According to [this thread](http://stackoverflow.com/questions/30459045/osx-safari-frame-load-interrupted) it might be a Safari problem. I'll test their solutions. – K Pat Mar 31 '16 at 18:35