Matthew Berman
Matthew Berman

Reputation: 8631

Google Analytics custom events not tracking properly

Here's the GA output code:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA_CODE']);
  _gaq.push(['_setDomainName', 'SUBDOMAIN']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackEvent', 'Priority', 'Created (day)', 'Label info', '']);



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

the trackEvent line seems to be correct...but not tracking for some reason. Is it because I left the value field nil?

Upvotes: 3

Views: 5051

Answers (2)

Nikolay
Nikolay

Reputation: 2214

I beleive _trackEvent won't work properly when called from GA tracking code snippet, at least it was not made for such usage. If you want to execute an event after page loads, try calling it for example from onLoad event of your body tag.

Secondly, passing an optional value parametr as '' would make it undefiened, which looks like it could produce an error, so, since it's optional, don't pass it at all.

And there's a delay in GA reportings, data processing takes about 24 hours (you can switch between new and old versions, sometimes one shows data faster than another).

Upvotes: 1

mike
mike

Reputation: 7177

For _trackEvent, the value parameter should be an integer. Since it's an optional parameter, you can just leave it out:

_gaq.push(['_trackEvent', 'Priority', 'Created (day)', 'Label info']);

Having a non-integer value will prevent the event from being tracked.

Upvotes: 6

Related Questions