GA Event Tracker - not working?

Discussion in 'Google Analytics' started by gordano, Aug 31, 2010.

  1. #1
    Has anyone managed to use the GA event tracker sucessfully?

    I am having poblems and am seeking suggestions. I have the GA code on the header of the pages and am using the event tracker code below

    <a href="http://www.mydomain/mydoc.pdf" target="_blank" onClick="javascript: pageTracker._trackPageview('http://www.mydomain/mydoc.pdf.pdf');">

    Can anyone see a problem with this code? ... below is the main page header code I am using ...

    <script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-1780XXX0-1']);
    _gaq.push(['_trackPageview']);

    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();

    </script>

    Thanks

    gordano :)
     
    gordano, Aug 31, 2010 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    When you attach an onclick event, you don't include the protocol (javascript:...) in there.

    replace this

    onClick="javascript: pageTracker._trackPageview('http://www.mydomain/mydoc.pdf.pdf');"
    Code (markup):
    with this

    onclick="return pageTracker._trackPageview('http://www.mydomain/mydoc.pdf.pdf') ? true : true;"
    Code (markup):
    I include the "return" to make sure that javascript executes before the visitor navigates away from the page.
     
    joebert, Aug 31, 2010 IP
  3. gordano

    gordano Active Member

    Messages:
    843
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    70
    #3
    Joebert

    Thanks for the suggestion. I tried this but still showing zero events tracked.

    It is puzzling me, if anyone on this forum can check the code and fix this for me I'll pay $10
     
    gordano, Sep 3, 2010 IP