Mike Eng
Mike Eng

Reputation: 1681

Google Analytics Event Tracking Code Not working

I am using Google Analytics Asynchronous tracking code and trying to track clicks on the "download" button on this download page. (It is normally accessed through a Shadowbox from its parent page quitnowri.com.)

At one point, the event tracking was working - I was able to get one download event tracked in my report.

But later, I changed the "download" button to force a download via php with this method.

The standard event tracking JavaScript onClick handler wasn't working (it is commented out on said download page), so I tried using the function from Google Analytics to delay pageload while tracking the event. This has not worked either after 5 days.

Any ideas?

Upvotes: 1

Views: 2695

Answers (2)

Mike Eng
Mike Eng

Reputation: 1681

It was indeed a problem with undefined JavaScript variables. The solution was.

In the head:

<script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXXXXX-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>
    <!-- delay to ensure that events are tracked http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55527-->
    <script type="text/javascript">
      function recordOutboundLink(link, trackEvent, category, action) {
        _gat._getTrackerByName()._trackEvent(trackEvent, category, action);
        setTimeout('document.location = "' + link.href + '"', 100);
      }
    </script>
<script type="text/javascript">
      function recordOutboundLink(link, trackEvent, category, action) {
        _gat._getTrackerByName()._trackEvent(trackEvent, category, action);
        setTimeout('document.location = "' + link.href + '"', 100);
      }
</script>

On the link:

<a href="download.php" id="download" class="download" name="Constant Reminder Ringtone" onClick="recordOutboundLink(this, 'Files', 'Download', 'Constant Reminder Ringtone');return false;">DOWNLOAD</a>

Upvotes: 1

therealsix
therealsix

Reputation: 654

FIREBUG

FIREBUG DUDE!

Upvotes: 2

Related Questions